Python Boolean

by Atakan

Hi,
The names of Pythonda boolean data types are True and False.
You must pay attention to this naming when using a condition.

print(type(True)) #<class 'bool'>

print(type(true))   #NameError: name 'true' is not defined

print(bool(0))  #False
print(bool(1))  #True


print(bool(""))  #False
print(bool("a"))  #True

my_string_var = "False"
print(type(my_string_var))  #<class 'str'>
my_bool_var = bool(my_string_var)
print(my_bool_var)  #True
print(type(my_bool_var))    #<class 'bool'>

my_string_var = ""
print(type(my_string_var))  #<class 'str'>
my_bool_var = bool(my_string_var)
print(my_bool_var)  #False
print(type(my_bool_var))    #<class 'bool'>

my_var_first = 1
my_var_second = 0
print(bool(my_var_first))   #True
print(bool(my_var_second))  #False

my_var_first = "1"
my_var_second = "0"
print(bool(my_var_first))   #True
print(bool(my_var_second))  #True

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. OK Read More