Python Tutorial: Booleans in Python - Python Numbers #37

preview_player
Показать описание

Python Booleans
In this Python tutorial, we will take a look at Python booleans. A boolean is a truth statement which is either True or False. You may be asking why we are looking at booleans in the numbers section of our Python tutorials. Well believe it or not booleans are actually integers. True is equal to one and False is equal to zero in Python. Truth statements are very useful when we use flow control statements which we will cover in full in a later tutorial.

Examples of Python Booleans
In the examples below focus on True and False. I throw some new operators like boolean operators and comparison operators which we will cover both in next two tutorials.

Example of Python Booleans

#Boolean Operators
True and True
True
True or True
True
not False
True

False
7 == 7
True
7 != 8
True

#Proof That a Boolean is actually an integer
True + False
1
type(True)
class 'bool'
a = True + False
type(a)
class 'int'
If you have any questions about booleans leave a comment below and we will do our best to help you understand.
Рекомендации по теме