
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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')
- Related Articles
- How to indent multiple if...else statements in Python?
- How to write an if-else statement in a JSP page?
- How to use if...else statement at the command line in Python?
- IF ELSE statement in a MySQL Statement?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- Java if-else statement
- How to use else statement with Loops in Python?
- Java if-else-if ladder statement
- Java if-then-else statement
- What is basic syntax of Python if...else statement?
- What is if...else if... statement in JavaScript?
- How to show if...else statement using a flowchart in JavaScript?
- Explain if-else statement in C language
- What is the syntax of Python if...elif...else statement?
- How to use else conditional statement with for loop in python?

Advertisements