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

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

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 13:04:11