Skip to main content

Lesson 08: Booleans (True or False)

Learn Python booleans for BIM automation: handle yes/no decisions, check conditions, validate designs, and automate logic in architectural workflows.

Introduction

Every decision in architecture involves yes or no questions.

Is the room compliant with code? Is the drawing issued? Does the area meet the minimum requirement?

In Python, these yes/no states are called booleans. They're named after George Boole, a mathematician who formalised logic.

Booleans are simple — they can only be True or False. But they're the foundation of every automated decision your scripts will make.

This lesson shows you how booleans work and how to use them to check conditions in architectural workflows.


Lesson Overview

This section contains a general overview of topics you will learn in this lesson.

  • Understand what booleans are (True/False values)
  • Learn comparison operators (>, <, ==, !=, >=, <=)
  • Use logical operators (and, or, not)
  • Store boolean results in variables
  • Apply booleans to architectural decision-making

What Is a Boolean?

A boolean is a data type with only two possible values:

True
False

That's it. Nothing else.

Notice: True and False are capitalised in Python. This matters.

is_issued = True      # Correct
is_approved = False   # Correct

is_issued = true      # Wrong (lowercase 't')
# Error: NameError: name 'true' is not defined

Where Booleans Come From

You can create booleans directly:

is_issued = True
is_approved = False
requires_review = True

Or you get them as the result of comparisons:

floor_area = 450
minimum_area = 400

meets_requirement = floor_area > minimum_area
print(meets_requirement)  # Output: True

Comparison Operators

Comparison operators compare two values and return True or False.

Greater Than (>)

floor_area = 450
minimum_area = 400

result = floor_area > minimum_area
print(result)  # Output: True

Less Than (<)

ceiling_height = 2.4
minimum_height = 2.7

result = ceiling_height < minimum_height
print(result)  # Output: True

Equal To (==)

room_count = 12
expected_count = 12

result = room_count == expected_count
print(result)  # Output: True

Important: Use == (double equals) for comparison, not = (single equals for assignment).

x = 5       # Assignment (creates/updates variable)
x == 5      # Comparison (checks if equal)

Not Equal To (!=)

status = "Draft"
required_status = "Issued"

result = status != required_status
print(result)  # Output: True (they are different)

Greater Than or Equal To (>=)

room_area = 400
minimum_area = 400

result = room_area >= minimum_area
print(result)  # Output: True (equal counts)

Less Than or Equal To (<=)

floor_count = 8
maximum_floors = 10

result = floor_count <= maximum_floors
print(result)  # Output: True

Architectural Examples: Comparisons

Checking Code Compliance

room_height = 2.4
minimum_height = 2.7

is_compliant = room_height >= minimum_height
print(is_compliant)  # Output: False

if is_compliant:
    print("Room meets code requirement")
else:
    print("Room height too low")

Checking Floor Area

room_area = 450
minimum_area = 400

meets_requirement = room_area > minimum_area
print(meets_requirement)  # Output: True

Validating Sheet Status

sheet_status = "Issued"
required_status = "Issued"

is_ready = sheet_status == required_status
print(is_ready)  # Output: True

Comparing Strings

You can compare strings using the same operators.

Equality

room_type_1 = "Conference Room"
room_type_2 = "Conference Room"

result = room_type_1 == room_type_2
print(result)  # Output: True

Warning: String comparisons are case-sensitive.

status_1 = "Issued"
status_2 = "issued"

result = status_1 == status_2
print(result)  # Output: False (different case)

# Fix: standardize case first
result = status_1.lower() == status_2.lower()
print(result)  # Output: True

Logical Operators

Logical operators combine multiple boolean values.

AND (and)

Both conditions must be True for the result to be True.

floor_area = 450
ceiling_height = 2.8

minimum_area = 400
minimum_height = 2.7

area_ok = floor_area >= minimum_area
height_ok = ceiling_height >= minimum_height

is_compliant = area_ok and height_ok
print(is_compliant)  # Output: True (both are True)

Truth Table for AND:

True  and True  = True
True  and False = False
False and True  = False
False and False = False

OR (or)

At least one condition must be True for the result to be True.

is_fire_rated = False
has_sprinklers = True

is_protected = is_fire_rated or has_sprinklers
print(is_protected)  # Output: True (one is True)

Truth Table for OR:

True  or True  = True
True  or False = True
False or True  = True
False or False = False

NOT (not)

Reverses a boolean value.

is_issued = False
needs_review = not is_issued
print(needs_review)  # Output: True

Truth Table for NOT:

not True  = False
not False = True

Architectural Examples: Logical Operators

Room Validation (Multiple Conditions)

room_area = 450
ceiling_height = 2.8
has_windows = True

# All conditions must be met
minimum_area = 400
minimum_height = 2.7

area_ok = room_area >= minimum_area
height_ok = ceiling_height >= minimum_height

is_valid = area_ok and height_ok and has_windows
print(is_valid)  # Output: True

Fire Safety Check (At Least One Must Be True)

has_fire_door = False
has_sprinklers = True
has_fire_alarm = True

is_safe = has_fire_door or has_sprinklers or has_fire_alarm
print(is_safe)  # Output: True (at least one is True)

Excluding Certain Conditions

is_basement = False
is_mechanical = False

is_habitable = not is_basement and not is_mechanical
print(is_habitable)  # Output: True

Combining Comparisons and Logic

You can write complex conditions in one line.

room_area = 450
ceiling_height = 2.8
is_basement = False

minimum_area = 400
minimum_height = 2.7

# Room is valid if it meets size requirements AND is not a basement
is_valid = (room_area >= minimum_area and
            ceiling_height >= minimum_height and
            not is_basement)

print(is_valid)  # Output: True

Order of Operations (Logical)

Python evaluates logical operators in this order:

  1. not (highest priority)
  2. and
  3. or (lowest priority)
result = True or False and False
print(result)  # Output: True
# Evaluates as: True or (False and False)
# Which is: True or False = True

Best Practice: Use parentheses to make your intent clear.

result = (True or False) and False
print(result)  # Output: False
# Now the or happens first

Boolean Values from Other Types

Some values are considered "truthy" or "falsy" in boolean contexts.

Falsy values (evaluate to False):

  • False
  • None
  • 0 (zero)
  • "" (empty string)
  • [] (empty list)
  • {} (empty dictionary)

Truthy values (evaluate to True):

  • Everything else
room_name = ""
has_name = bool(room_name)
print(has_name)  # Output: False (empty string)

room_name = "Conference Room"
has_name = bool(room_name)
print(has_name)  # Output: True (non-empty string)

This becomes useful later when checking if variables have values.


The Pain vs The Python Fix

The Pain: Manually checking if 500 rooms meet code requirements. One by one. In a spreadsheet.

The Python Fix: Define the rule once, check all rooms automatically.

# Room data (simplified)
rooms = [
    {"name": "Conference A", "area": 450, "height": 2.8},
    {"name": "Conference B", "area": 380, "height": 2.9},
    {"name": "Office 1", "area": 420, "height": 2.6},
    {"name": "Office 2", "area": 410, "height": 2.8}
]

# Requirements
minimum_area = 400
minimum_height = 2.7

# Check each room
for room in rooms:
    area_ok = room["area"] >= minimum_area
    height_ok = room["height"] >= minimum_height
    is_compliant = area_ok and height_ok

    if is_compliant:
        print(f"{room['name']}: PASS")
    else:
        print(f"{room['name']}: FAIL")

# Output:
# Conference A: PASS
# Conference B: FAIL (area too small)
# Office 1: FAIL (height too low)
# Office 2: PASS

Common Mistakes

Mistake 1: Using = instead of ==

floor_count = 10

# Wrong (assignment, not comparison)
if floor_count = 10:
    print("Ten floors")
# Error: SyntaxError: invalid syntax

# Correct (comparison)
if floor_count == 10:
    print("Ten floors")

Mistake 2: Comparing booleans explicitly

You don't need to compare booleans to True or False.

is_issued = True

# Redundant
if is_issued == True:
    print("Issued")

# Better
if is_issued:
    print("Issued")

Mistake 3: Confusing and/or logic

# You want: area > 400 OR height > 2.7
area = 380
height = 2.8

# Wrong (both conditions must be true)
is_ok = area > 400 and height > 2.7
print(is_ok)  # Output: False

# Correct (at least one must be true)
is_ok = area > 400 or height > 2.7
print(is_ok)  # Output: True

Mistake 4: Forgetting operator precedence

x = True
y = False
z = True

# Without parentheses (not happens first)
result = not x and y or z
print(result)  # Output: True

# With parentheses (clear intent)
result = (not x) and (y or z)
print(result)  # Output: False

When in doubt, use parentheses.


Assignment

  1. Create a new file called boolean_practice.py
  2. Room compliance checker:
    • Create variables: room_area = 420, ceiling_height = 2.6
    • Set requirements: minimum_area = 400, minimum_height = 2.7
    • Check if room meets both requirements using and
    • Print "Compliant" or "Not Compliant"
  3. Project status validator:
    • Variables: design_complete = True, permits_approved = False, budget_approved = True
    • Project can proceed if ALL three are True
    • Check and print result
  4. Floor eligibility checker:
    • Variables: floor_number = 0, is_mechanical = False
    • A floor is habitable if it's NOT floor 0 AND NOT mechanical
    • Use not operator
    • Print result
  5. Multiple room checks:
    • Create a list of room areas: [380, 420, 450, 390]
    • Minimum area: 400
    • For each area, check if it meets minimum and print result
  6. String comparison practice:
    • Variables: status_1 = "Issued", status_2 = "issued"
    • Compare directly (case-sensitive)
    • Compare after converting to lowercase
    • Observe the different results
  7. Experiment:
    • Try using = instead of == in a comparison (see the error)
    • Try: True and False or True — what's the result?
    • Try: (True and False) or True — is it different?
    • Check if an empty string is truthy or falsy using bool("")

Knowledge Check

The following questions are an opportunity to reflect on key topics in this lesson.


Additional Resources

This section contains helpful links to related content. It isn't required, so consider it supplemental.

Updated on Mar 27, 2026