Skip to content
Lesson 1 of 9 Free Preview
Duration: 20 min

Boolean Logic: AND, OR, NOT

Learn it

A Boolean value is either True or False. We combine them with:

  • and: True only if both are True.
  • or: True if at least one is True.
  • not: flips True and False.
A B A and B A or B
True True True True
True False False True
False True False True
False False False False

🧰 Tool: any free online Python editor such as Online Python or Trinket, or install Python from python.org and use IDLE.

Code examples

Python

has_ticket = True
is_tall_enough = False
print(has_ticket and is_tall_enough)  # False
print(has_ticket or is_tall_enough)   # True
print(not is_tall_enough)             # True

age = 11
print(age >= 9 and age <= 12)         # True

Text after # is a comment: Python ignores it.

Project: Theme park rules

  1. Write rules for a ride using and/or (age, height, with an adult).
  2. Turn them into Python with variables.
  3. Test 4 different visitors.

Challenge: Write a truth table for not (A and B).

Enjoying this lesson?

Enroll in the full course to access all lessons, track your progress, and earn a certificate.

Enroll in Full Course