Usage of and, or, not Logical Operators
Logical operators are often combined with conditional statements like if, and else to control the flow of a program.
Types of Logical Operators
In Python, you can use the following logical operators:
-
and: ReturnsTrueif both values on either side of the operator are true. -
or: ReturnsTrueif at least one of the values on either side of the operator is true. -
not: Returns the opposite of the given Boolean value.
Example of Logical Operators Usage
is_student = True has_id = False # AND operation print(is_student and has_id) # False # OR operation print(is_student or has_id) # True # NOT operation print(not is_student) # False
Quiz
0 / 1
The logical operator and returns True only when both Boolean values are True.
True
False
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result