
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between OR and AND Operators in Python
The OR and AND operators are the most commonly used logical operators. The logical operators are used to perform decision-making operations. These combine multiple conditions and make a decision based on them. In this article, we will understand what OR and AND operators are in Python and how they differ, along with examples for better understanding.
AND Operator in Python
The logical AND operator in Python needs two operands. It returns true if both operands are true, and it returns false if either of the operands is false. This operator is mostly used in situations where you want to make sure that two things are true at the same time.

Example of the AND Operator
The following is an example of an AND operator in Python. In the example below, we are checking the eligibility of a person to vote. One variable has been assigned a Boolean value, and the other variable is performing a comparison operation to check if the age is above 18. Based on these values, the AND operator prints the resultant text.
age = 22 has_voter_id = True if age >= 18 and has_voter_id: print("You are eligible to vote.") else: print("Sorry, you are not eligible to vote.")
Following is the output of the above program -
You are eligible to vote.
OR Operator in Python
The logical OR operator also needs two operands. The OR operator in Python returns true if one of the operands is true, and it returns false if both operands are false. This operator is used in situations where only one operand needs to be true.

Example of OR Operator
The following is an example of an OR operator in Python. In here, both variables have been assigned Boolean values, and based on these values, the OR operator prints the resultant text.
is_hungry = False is_thirsty = True if is_hungry or is_thirsty: print("Time for a snack or a drink!") else: print("All good for now!")
Following is the output of the above program -
Time for a snack or a drink!