Data Types - Booleans
The Boolean data type is a value of – True / False.
It is very common that python functions return a Boolean value.
A Boolean can be the product of a comparison operator.
#Booleans print("is 1 equals to 2? ", 1==2) type(1 == 1)
It is important to know that the Boolean type can be translated to numbers.
- True --> 1
- False --> 0
Here is an example:
#Booleans print(True + False) print(True + True) print(True + 1) print(True / False)
In the example above we tried to divide (1/0). It returns a ZeroDivisionError.
Please notice while using conditional statements – notice that any number but zero is evaluated as True. Zero is the only number evaluated as False. Here is an example:
#Booleans if 5: print(5) if 0: print(0)