Lecture
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
Lessons in this chapter · Boolean Data Type and Logical Operators
- 1. Boolean Data Type for Determining True or False
- 2. Generating Boolean Values with Comparison Operators
- 3. Usage of and, or, not Logical Operators
- 4. Multiple-choice quiz
- 5. Checking if Two Objects Are Identical with the is Operator
- 6. The not Operator Returning the Opposite
- 7. Combining Boolean Values with and, or Operators
- 8. Coding Quiz - Compare Values
- 9. Multiple-choice quiz
- 10. Fill-in-the-blank quiz
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