
- 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 style multi-line conditions in 'if' statements in Python?
There are many ways you can style multiple if conditions. You don't need to use 4 spaces on your second conditional line. So you can use something like &minusl;
if (cond1 == 'val1' and cond2 == 'val2' and cond3 == 'val3' and cond4 == 'val4'):
# Actual code
You can also start the conditions from the next line −
if ( cond1 == 'val1' and cond2 == 'val2' and cond3 == 'val3' and cond4 == 'val4' ):
# Actual code
Or you can provide enough space between if and ( to accomodate the conditions in the same vertical column.
if (cond1 == 'val1' and cond2 == 'val2' and cond3 == 'val3' and cond4 == 'val4'):
# Actual code
You can also do this without brackets, but note that PEP8 guidelines discourage this. For example,
if cond1 == 'val1' and cond2 == 'val2' and \ cond3 == 'val3' and cond4 == 'val4':
# Actual code
- Related Articles
- Multi-Line Statements in Python
- How do we write Multi-Line Statements in Python?
- How to execute Python multi-line statements in the one-line at command-line?
- How to comment each condition in a multi-line if statement in Python?
- Multi-Line printing in Python
- How to create a long multi-line string in Python?
- How to write multi-line comment in Java?
- How to write multi-line comments in C#?
- How to create multi-line strings in JavaScript?
- How to provide multiple statements on a single line in Python?
- How to put multi-line comments inside a Python dict()?
- How to use multiple conditions in one if statement in Python?
- How to indent multiple if...else statements in Python?
- How can we combine multiple print statements per line in Python?
- C-style parser for command line options in Python

Advertisements