Python Booleans

A colourful cartoon-style landscape illustration shows a smiling robot holding up two placards: one clearly labelled True and the other False. The background is bright and cheerful, symbolising the concept of Boolean values in Python programming.

A Boolean (named after the mathematician George Boole) is a special data type that has only two possible values:

  • True
  • False

These are not strings (they don’t have quotes around them) and they must be written with a capital T or capital F.

Booleans are used for making decisions in your code, such as “Should I do this or not?”.

Comparison operators

Booleans often come from comparisons. Python checks something, and the result is either True or False.

OperatorExampleResult
==5 == 5True
!=5 != 3True
<2 < 7True
<=7 <= 7True
>10 > 3True
>=3 >= 4False

Try this

  • Print whether 15 is greater than 20.
  • Print whether 7 is equal to 7.
  • Print whether "apple" != "orange".

Boolean operators (and, or, not)

You can combine Booleans with logical operators:

  • and → True only if both sides are True
  • or → True if at least one side is True
  • not → flips True to False (and False to True)

Example with numbers:

Try this

  • Make age = 16. Print whether age is greater than 13 and less than 19.
  • Check if "dog" is equal to "cat" or "dog".
  • Use not to flip a True value into False.

Using Booleans in decisions (if statements)

Booleans are most powerful when combined with if statements to control what your program does.

You don’t need to write == True or == False. The Boolean itself is enough.

Try this

  1. Ask the user their age.
  2. Convert it to an integer.
  3. Print "You are an adult" if they are 18 or over, otherwise print "You are a minor".

Converting to Booleans

You can convert values into Booleans with the bool() function.

Python treats some values as False: 0, 0.0, "" (empty string), None, and empty lists. Everything else is considered True.

Try this

  • Print bool(100).
  • Print bool("").
  • Print bool("Python").

Common beginner mistakes

  • Forgetting the capital letters: true and false don’t work — it must be True and False.
  • Thinking Booleans are strings: "True" is not the same as True.
  • Writing conditions like if is_sunny == True: when simply if is_sunny: is better.

Summary

  • A Boolean is either True or False.
  • Comparisons (==, <, >) return Booleans.
  • Use and, or, not to combine conditions.
  • Booleans control program flow with if statements.
  • bool() converts values into True or False.

✅ With Booleans, your programs can start making decisions and reacting to different situations. This is the foundation of logic in coding.

Main Topic

Python Fundamentals

A colourful cartoon-style landscape illustration shows a person sitting at a computer terminal, looking overwhelmed by the amount of information on the screen. Papers and symbols float around them, representing different programming concepts. The word “Fundamentals” is clearly written above the scene, highlighting the focus on beginner Python basics.

Beginner’s guide to Python fundamentals: strings, numbers, booleans, syntax, and text manipulation explained simply and clearly.

Other Tutorials in this Topic

A playful cartoon-style landscape illustration shows a large elephant on the left and a small cat on the right. Between them, a bold greater than ( > ) symbol points toward the cat, representing a Python comparison operator in a fun way.

Python Operators

Beginner’s guide to Python operators: arithmetic, comparison, logical, assignment, membership, and identity explained with examples.

ChatGPT said: A colourful cartoon-style landscape illustration shows two large labelled containers: one marked Integers filled with whole numbers like 7, 0, and -3, and another marked Floats filled with decimal numbers like 3.14, -0.5, and 2.0. A cheerful character is sorting the numbers into the correct containers, visually explaining the difference between integers and floating-point numbers in Python.

Python Numbers

Learn Python numbers: integers and floats, arithmetic operations, conversions, rounding, precision issues, and practical exercises for beginners…

A colourful cartoon-style landscape illustration shows the text “python ” written across the scene. Above the gap, a labelled box with the word “strings” is tilted, pouring its contents into the space, visually representing a variable being used to fill in a placeholder.

Python Strings – Part 4

Discover Python string formatting: use f-strings, .format(), and number formatting to neatly combine variables and text into…

A colourful cartoon-style landscape illustration shows the words “python strings” in lowercase being fed into a large whimsical machine. On the other side, the text emerges transformed into “PYTHON STRINGS” in uppercase letters, symbolising string methods like .upper(). The machine has gears and pipes, giving a fun and playful feel.

Python Strings – Part 3

Learn Python string methods: change case, remove spaces, replace text, split and join words, and check content…

A digital landscape illustration shows a beige fabric banner with the words “Python Strings” written across it. The material is ripped down the centre, with large visible stitches crudely sewing the two halves back together, symbolising fixing or escaping characters in strings. The background is simple and muted, drawing attention to the torn fabric.

Python Strings – Part 2

Explore Python strings further: escape characters, multi-line strings, and slicing to extract parts of text, with simple…

A colourful cartoon-style landscape illustration shows festive bunting strung across the top, with triangular flags spelling out “Python Strings” in bright, playful letters. The background is light and cheerful, giving a fun and welcoming atmosphere.

Python Strings – Part 1

Learn Python strings: text in quotes, printing, joining with +, counting length, and accessing characters by position…

A colourful cartoon-style illustration shows a confused student with orange hair shrugging in front of a computer screen. The screen displays a Python function with a missing indentation error:

Python Syntax

Learn Python syntax basics with clear examples and beginner-friendly practice exercises.

A cartoon-style illustration shows a person’s hands typing on a laptop running Visual Studio Code in dark mode. The screen displays a Python file with the code print("Hello, world!"), alongside a large, colourful Python logo. The background is bright blue, creating a vibrant and engaging learning atmosphere.

Start Coding Python with VS Code

Beginner’s guide to installing Python, setting up VS Code, and getting ready for coding.

Python Variables

Python Variables

Learn Python variables with simple explanations, real-world analogies, practice tasks to build confidence using data in programs.