Boolean Type in Python
In computer science, booleans has two values which can be either true or false. Boolean values represents truth value of the logic and boolean algebra.
In python there are two constants, True and False, that can be used to assign value directly. Python expects an expression to evaluate to a boolean value. These places are called boolean contexts. We can write any expression in boolean contexts.
Why True/False is capitalized in Python?
I already told you that "True" and "False" all built-in constants of Python are capitalized or [upper] CamelCase.
In Python booleans can be treated as numbers. A True value is 1 and a False value is 0. You can also do any operation between boolean values in Python.
a=True b=True print(a+b)
Output of the above result will be 2.
Following are some examples of boolean operations
How to check the type of any boolean value?
The type function returns the datatype of any arbitrary object.This is useful functions that can handle several types of data.
a=True print(typeof(a)) b=False print(typeof(b))