typestar

Booleans and comparisons in Python

True and False, and the expressions that produce them.

age = 34
has_ticket = True

is_adult = age >= 18
can_enter = is_adult and has_ticket
needs_help = not is_adult or age > 65

empty = bool("")
full = bool("text")
zero = bool(0)

in_range = 0 <= age < 120

How it works

  1. Comparison operators return booleans directly.
  2. and, or, not combine simple checks into rules.
  3. bool shows truthiness: empty things are falsy.
  4. Comparisons chain: 0 <= age < 120 reads like math.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
202
Tokens
54
Three-star pace
80 tpm

At the three-star pace of 80 tokens a minute, this run takes about 40 seconds.

Type this snippet

Step 3 of 6 in Variables & types, step 3 of 72 in Language basics.

← Previous Next →