, asked
Views : 2

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

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

1 Answer
Malhar Lathkar

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

For example

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

Advertisements
Related Questions