- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is different in OR and AND operators in Python?
In Python, and and or (along with not) are defined as logical operators. Both require two operands which may evaluate to true or false.
The and operator returns True only if both operands are True.
>>> a=50 >>> b=25 >>> a>40 and b>40 False >>> a>100 and b<50 False >>> a==0 and b==0 False >>> a>0 and b>0 True
The or operator returns True if either operand is true.
>>> a=50 >>> b=25 >>> a>40 or b>40 True >>> a>100 or b<50 True >>> a==0 or b==0 False >>> a>0 or b>0 True
Advertisements