Python Booleans
Python Booleans
Boolean consists of only two values; True and False.
Why are Boolean’s needed?
Consider the following if-else statement:
Is it True that X is greater than 13 or is it False?
- Thus Booleans are used to know whether the given expression is True or False.
- bool() function evaluates values and returns True or False.
Here are some examples where the Boolean returns True/False values for different datatypes.
None:
Output:
Numbers:
Output:
Strings:
Output:
Lists:
Output:
Tuples:
Output:
Sets and Dictionaries:
Output: