Booleans represent one of two values: True or False. Is used in if statement in Python. If it’s true execute the block of code or else skip it.
Note: don’t forget capital T and F, it is case sensitive
Example boolean if in Python
Let’s check if boolean is true Python
var = True if var: print('var is True') else: print('var is False')
More boolean Python examples
my_boolean = 1 print(bool(my_boolean)) my_boolean = 0 print(bool(my_boolean)) my_boolean = 10 print(bool(my_boolean)) print("Coding" == "fun")
Do comment if you have any doubts and suggestions on this Python basic topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.