Booleans and None

A boolean is a yes-or-no value.

Python has two boolean values:

Booleans appear when you compare values:

Output:

True
False

Comparisons

Common comparison operators:

OperatorMeaning
<less than
<=less than or equal to
>greater than
>=greater than or equal to
==equal value
!=not equal value

Use == for comparison. A single = is assignment.

Boolean Names

Boolean names often read like questions:

That style helps later when conditions appear:

You do not need to master if statements yet. For now, know that booleans are the values conditions use.

None

None represents the intentional absence of a value.

Output:

None

Use None when a name exists, but no meaningful value has been assigned yet.

Example:

best_loss = None

This says, "we have a name for the best loss, but no run has produced one yet."

None Is Not False or Zero

None, False, and 0 are three different values with different meanings:

Both comparisons print False. Use None to mean “no value is available,” not as another spelling of a negative answer or the number zero. Later, when you write conditions, you will usually check for this value with value is None.

Capitalization Matters

Do not write booleans in lowercase:

Python uses:

Exercise: Compare values

What does this expression produce?

10 > 3
Choose one

Select one choice, then check.

HintRead the comparison aloud

Ask: “Is ten greater than three?”

SolutionThe comparison is true

Ten is greater than three, so 10 > 3 produces the boolean value True.

Use Booleans for Decisions

Booleans help programs decide. None helps programs represent "not available yet." Both are small values with large roles in real code.