
- 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 use multiple conditions in one if statement in Python?
You can use a combination of conditions in an if statement. All your conditions need to be defined using some sort of logic. For example, to check if a number is divisible by both 3 and 5, you can use −
Example
a = 15 if a % 3 == 0: if a % 5 == 0: print("Divisible by both")
Output
This will give the output −
Divisible by both
Example
You can convert it to a single if using the and operator −
a = 15 if a % 3 == 0 and a % 5 == 0: print("Divisible by both")
Example
This will give the output −
Divisible by both
There are other operators like or, not, etc that you can use to build more complex logic.
- Related Articles
- MySQL If statement with multiple conditions?
- How to override multiple if-else conditions using a switch statement in TypeScript?
- How to use nested if statement in Python?
- How to use multiple modules with Python import Statement?
- How to use IF statement in MySQL using Python?
- How to use multiple font sizes in one label in Python Matplotlib?
- How to use if...else statement at the command line in Python?
- How to use continue statement in Python loop?
- How to work multiple AND conditions in MySQL?
- Display records with conditions set using if statement in UPDATE statement with MySQL
- How to use else statement with Loops in Python?
- How to use OR condition in a JavaScript IF statement?
- How to update array with multiple conditions in MongoDB
- Can we use break statement in a Python if clause?
- Can we use continue statement in a Python if clause?

Advertisements