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
: ReturnsTrue
if both values on either side of the operator are true. -
or
: ReturnsTrue
if 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
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.