Python, from Zero, for AILesson 8 of 89

Module 1 · Getting Python running, and your first working code

True, False, and what Python counts as nothing

In this lesson

  • 7 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 8 of 10 in this chapter

This chapter’s goalInstall Python on a laptop, a phone or a free browser machine, run the same code both interactively and from a saved file, and predict what a short program prints by naming the type of every value in it and the branch a condition takes.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:49Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

Comparisons produce a value you can store

Python
>>> 5 > 3
True
>>> age = 17
>>> can_vote = age >= 18
>>> can_vote
False

True and False are values like any other. You can put them in a variable, in a list, pass them to a function. They are capitalised: true is a NameError.

The comparison operators: == equal, != not equal, <, >, <=, >=. And two that read like English: in for membership, not in for its opposite.

Python
"a" in "cat"                 # True
3 in [1, 2, 3]               # True
"rent" in {"food": 200}      # False — dicts check keys

Python allows chained comparisons, which most languages do not:

Python
score = 85
if 0 <= score <= 100:
    print("score is in range")

That means what it looks like. C evaluates that line differently. Java rejects it at compile time.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘True, False, and what Python counts as nothing’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/booleans-and-truth (Accessed: 21 November 2026).