Boolean in Python
What is a Boolean?
Ture or False (Make sure to use initial letter as a capital)
For Example,
>>> True
True
>>> true
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'true' is not defined
>>> true
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'true' is not defined
Examples:
>>> x= True
>>> type(x)
<class 'bool'>
>>> type(x)
<class 'bool'>
>>> 9 > 8
True
>>> 8> 9
False
How to define/assign a variable without value?
>>> x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
Here is the way, you could define the variable without defining/assigning the value
>>> x=None
>>> x
>>> x=None
>>> x
Comments
Post a Comment