Python If Condition with OR Operator - Examples


Python If OR

You can combine multiple conditions into a single expression in an If statement, If-Else statement, or Elif statement using logical operator OR.

Python OR logical operator returns True if at least one of the two operands provided is True. Refer Python OR logical operator tutorial for syntax and truth table.

Examples

In the following examples, we will see how we can use Python OR logical operator to form a compound condition in conditional statement.

1. Python If with OR operator in condition

In the following example, we will learn how to use Python or operator to join two simple boolean conditions to form a compound boolean condition in a Python If statement.

Python Program

today = 'Saturday'

if today=='Sunday' or today=='Saturday':
	print('Today is off. Rest at home.')

Output

Today is off. Rest at home.

Here, today=='Sunday' and today=='Saturday' are two simple conditions. We have used and operator to join these two simple conditions and create a compound condition: today=='Sunday' or today=='Saturday' .

2. Python If-Else with OR operator in condition

In the following example, we will use or operator to combine two basic conditional expressions in boolean expression in a Python If Else statement.

Python Program

today = 'Wednesday'

if today=='Sunday' or today=='Saturday':
	print('Today is off. Rest at home.')
else:
	print('Go to work.')

Output

Go to work.

3. Python Elif with OR operator in condition

In the following example, we will use or operator to combine two basic conditional expressions in boolean expression of a Python elif statement.

Python Program

today = 'Sunday'

if today=='Monday':
	print('Your weekend is over. Go to work.')
elif today=='Sunday' or today=='Saturday':
	print('Today is off.')
else:
	print('Go to work.')

Output

Today is off.

Summary

In this tutorial, we learned how to use Python OR logical operator in If, If-Else and Elif conditional statements, with well detailed examples.