Check Multiple Conditions in If Statement (Python)
# Using Multiple Conditions in If Statements
The `if` statement is a powerful tool in Python that allows you to control the flow of your program. It is often used to evaluate a certain condition and, based on the result, execute a specific block of code. One great feature of the `if` statement is that you can use it to evaluate multiple conditions at the same time. In this tutorial, we will discuss how to check multiple conditions in an `if` statement in Python.
By combining various conditions in an `if` statement, you can make complex decisions in your code. This is useful when you want to take different actions based on different inputs. For instance, if you want to display different messages based on a user's input, you can use an `if` statement with multiple conditions to determine which message to display.
The `if` statement can be used with a variety of conditions, including comparison operators, logical operators, and identity operators. We will discuss each of these and demonstrate how to combine them to create complex conditions. We will also discuss the use of `if-elif-else` statements when multiple conditions must be evaluated in a certain order. Finally, we will show how to use the `any` and `all` functions to check multiple conditions in a simple and concise way.
Worried About Failing Tech Interviews?
Attend our webinar on
"How to nail your next tech interview" and learn
.png)
Hosted By
Ryan Valles
Founder, Interview Kickstart

Our tried & tested strategy for cracking interviews

How FAANG hiring process works

The 4 areas you must prepare for

How you can accelerate your learnings
Register for Webinar:
## Algorithm
1. Declare a Boolean expression or a series of Boolean expressions that need to be evaluated
2. Create an if statement with the Boolean expressions as the condition
3. If the Boolean expressions evaluate to True, execute the code in the if statement
4. If the Boolean expressions evaluate to False, skip the code in the if statement and continue with the rest of the code
## Sample Code
```python
if (x == 5 and y == 10) or (x == 10 and y == 5):
print("x and y are equal")
else:
print("x and y are not equal")
```