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
trueto beTrue. - Create a new variable
falseto beFalse.
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules