Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Boolean Basics | Booleans and Comparisons
Data Types in Python

bookBoolean Basics

Every decision your program makes—whether to show a message, repeat a step, or validate input—boils down to a Boolean: True or False. This chapter introduces Booleans and how ordinary Python values behave in conditions.

What is a Boolean?

A Boolean is a value that represents truth: True or False (note the capitalization). You'll often get Booleans from comparisons—age >= 18 yields True when the condition holds—and you'll use them directly in control flow, e.g. if is_adult:.

Truthiness in practice

In if/while conditions, Python treats many objects as "truthy" or "falsey". Empty or zero-like values are considered false; everything else is true. This lets you write natural checks such as if items: or if name: without extra comparisons.

Common falsey values

  • False;
  • None;
  • 0, 0.0;
  • "" (empty string);
  • Empty containers: [], (), {}, set().

Non-empty strings are truthy—even "0" or "False".

12345678910
is_ready = True name = "" count = 0 if is_ready: print("Go!") # runs, because True print(bool(name)) # False → empty string print(bool(count)) # False → zero print(bool("0")) # True → non-empty string
copy

1. Which value is falsey in Python?

2. What value will this code output?

3. Which if will not execute its body?

question mark

Which value is falsey in Python?

Select the correct answer

question mark

What value will this code output?

Select the correct answer

question mark

Which if will not execute its body?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 1

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Awesome!

Completion rate improved to 5

bookBoolean Basics

Pyyhkäise näyttääksesi valikon

Every decision your program makes—whether to show a message, repeat a step, or validate input—boils down to a Boolean: True or False. This chapter introduces Booleans and how ordinary Python values behave in conditions.

What is a Boolean?

A Boolean is a value that represents truth: True or False (note the capitalization). You'll often get Booleans from comparisons—age >= 18 yields True when the condition holds—and you'll use them directly in control flow, e.g. if is_adult:.

Truthiness in practice

In if/while conditions, Python treats many objects as "truthy" or "falsey". Empty or zero-like values are considered false; everything else is true. This lets you write natural checks such as if items: or if name: without extra comparisons.

Common falsey values

  • False;
  • None;
  • 0, 0.0;
  • "" (empty string);
  • Empty containers: [], (), {}, set().

Non-empty strings are truthy—even "0" or "False".

12345678910
is_ready = True name = "" count = 0 if is_ready: print("Go!") # runs, because True print(bool(name)) # False → empty string print(bool(count)) # False → zero print(bool("0")) # True → non-empty string
copy

1. Which value is falsey in Python?

2. What value will this code output?

3. Which if will not execute its body?

question mark

Which value is falsey in Python?

Select the correct answer

question mark

What value will this code output?

Select the correct answer

question mark

Which if will not execute its body?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 1
some-alt