Python Booleans

We'll cover the following

Python booleans

Boolean is a fundamental data type in Python. A boolean value can be represented as either True or False.

We can set booleans to different variables to represent truthy or falsy values. For instance, let’s say you haven’t yet completed the boolean lesson. In that case, the value of our completed variable will be set to False.

completed_lesson = False
print(completed_lesson)

By the end of this lesson, we can update it to True.

completed_lesson = True
print(completed_lesson)

Boolean variables can be added to depict different kinds of information in a class or object.

person_information = {"name": "X12", "age": 21, "python_developer": True}
print(person_information["python_developer"])

The person_information is a dictionary containing different information on a person, including the name, age and whether or not they’re a Python developer python_developer (i.e., a Boolean value).

Boolean type

Let’s try printing the type of the boolean values.

print(type(True))
print(type(False))