Overview of Boolean Type¶
Let us get into the details related to Boolean.
- Boolean typically will have
True
orFalse
. In Python it is defined asbool
. - You can assign boolean value by saying
a = True
ora = False
. - All comparison operators which we will be seeing as part of the next topic will return bool type.
not
can be used to get the negation of thebool
value.
In [1]:
a = True
In [2]:
a
Out[2]:
True
In [3]:
type(a)
Out[3]:
bool
In [4]:
a = False
In [5]:
type(a)
Out[5]:
bool
In [6]:
type(a) == bool
Out[6]:
True
In [7]:
# Assigning 10 to i
i = 10
In [8]:
# Comparing i with some number
# Returns True
i == 10
Out[8]:
True
In [9]:
# Comparing i with some value of type string
# Returns False
i == '10'
Out[9]:
False
In [10]:
type(i == 10)
Out[10]:
bool
In [11]:
type(i == '10')
Out[11]:
bool
In [12]:
i = 10
In [13]:
i == 10
Out[13]:
True
In [14]:
not i == 10
Out[14]:
False