- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to comment each condition in a multi-line if statement in Python?
You can do this directly if you are surrounding your multiline if statements conditions in a parenthesis. For example,
if (cond1 == 'val1' and cond2 == 'val2' and # Some comment cond3 == 'val3' and # Some comment cond4 == 'val4'):
However, this is not possible if you try to do this without a parenthesis. For example, the following code will give an error:
if cond1 == 'val1' and \ cond2 == 'val2' and \ # Some comment cond3 == 'val3' and \ # Some comment cond4 == 'val4':
- Related Articles
- How to write multi-line comment in Java?
- Statement, Indentation and Comment in Python
- How to use OR condition in a JavaScript IF statement?
- How to style multi-line conditions in 'if' statements in Python?
- How to create a long multi-line string in Python?
- Multi-Line printing in Python
- Multi-Line Statements in Python
- How to use if...else statement at the command line in Python?
- How to write single line comment in Java?
- How to execute Python multi-line statements in the one-line at command-line?
- How to put multi-line comments inside a Python dict()?
- How do we write Multi-Line Statements in Python?
- How to write multi-line comments in C#?
- How to use nested if statement in Python?
- Plot a multicolored line based on a condition in Python Matplotlib

Advertisements