Editor settings

General settings

Save settings

Learn to program with Python

Boolean data type #

The boolean data type is a logic or a truth value that is important in programming in all languages, especially for controlling the program's execution. There are two types of Boolean data, True and False.

In Python, we can define a Boolean value using the words True or False (the first letter must be capitalized) because the words true or false would be considered variable names.

For example:

x = True
print(x) # True
print(type(true)) # NameError: name 'true' is not defined.

From the example above, when we call the function print() with the word true, we get the NameError: name 'true' is not defined., because we did not spell True correctly.


Exercise #

  • Create a new variable true to be True.
  • Create a new variable false to be False.
Output will be displayed here