How to use OR operator in Python If Statement?

Python If with OR

You can combine multiple conditions into a single expression in Python if, Python If-Else or Python Elif statements.

In the following examples, we will see how we can use python or logical operator to form a compound logical expression.

Python OR logical operator returns True if one of the two operands provided to it evaluates to true.

Example 1: Python If Statement with OR Operator

In the following example, we will learn how to use python or operator to join two boolean conditions to form a boolean expression.

Python Program

today = 'Saturday'

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

Output

Today is off. Rest at home.

Example 2: Python If-Else Statement with OR Operator in Condition/Expression

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

Python Program

today = 'Wednesday'

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

Output

Go to work.

Example 3: Python elif Statement with OR Operator in Condition/Expression

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

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.')
Run this program

Output

Today is off.

Summary

In this tutorial of Python Examples, we learned how to use Python or logical operator with Python conditional statement: if, if-else and elif with well detailed examples.

Leave a comment

Your email address will not be published. Required fields are marked*