Trying out Booleans

What happens when we type Boolean values in the interpreter?

>>> True

True

>>> False

False

When the words 'True' and 'False' begin with upper case letters, Python knows that it should treat them like Booleans instead of strings or integers.

What happens when you type the words true and false in all lower case letters?

>>> true

>>> false

Did you get errors? That's because Python thinks these are variables.

Let's try using Python's type() function to see what's a Boolean and what isn't.

>>> type(True)

>>> type("True")

>>> type(true)

Answers

>>> type(True)

<class 'bool'>

>>> type("True")

<class 'str'>

>>> type(true)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

NameError: name 'true' is not defined