PyPyPath

Module 3: Operators in Python

Logical Operators

Logical operators combine True/False values: and (both must be true), or (at least one true), not (flip true/false).

About 8 minutes

and needs BOTH true

Condition A

True?

A and B

True only if both

Example code
has_ticket = True
is_adult = True
print(has_ticket and is_adult)  # True

print(True or False)   # True
print(not True)        # False
Practice

Create has_id and has_permission booleans. Print results of and, or, and not.

Key takeaways

  • and — both true; or — at least one true; not — opposite.
  • Logical operators work on bool values.
  • Perfect for combining checks in conditions.

Quick check: Logical Operators

Question 1 of 2

True and False equals?