How to indent an if...else statement in Python?


One of the characteristic features of Python is use of uniform indent to denote a block of statements. A block is initiated by − symbol As soon as − symbol is typed and enter pressed, any Python aware editor will take cursor to next line with increased indent. All lines entered subsequently will follow same level of indent. To signal end of block, indent level must be reduced by pressing backspace.

Using above procedure give − after if statement and write statements in true block. Then dedent by backspace and write else − In another block of increased indent enter statements in else block

if expr==True:
    stmt1
    stmt2
else:
    stmt3
    stmt4

example

marks=60
if marks>50:
    print ('pass')
else:
    print ('fail')

Updated on: 18-Jun-2020

591 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements