To convert the boolean value False to 0 in Python, you can use int(). int() converts False to 0 explicitly.
print(int(False))
#Output:
0
You can also convert False to 0 implicitly in the following way.
print(False == 0)
#Output:
True
When working with different variable types in Python, the ability to easily convert between those types can be valuable.
One such situation is if you have boolean variables and want to convert them to integers.
In Python, you can use the int() function to explicitly convert boolean values True and False into 1 and 0, respectively.
Below shows you how you can use int() to convert False to 0 explicitly.
print(int(False))
#Output:
0
If want to implicitly convert False to 0, you can let Python do it for you as False is equal to 0.
print(False == 0)
#Output:
True
Convert True to 1 in Python
If you want to go the other way and convert True into an integer, you can use int().
True is equal to 1, but if you want to do the conversion explicitly. then you can use int() in the following way.
Below shows you how to convert True to 1 in Python.
print(int(False))
#Output:
1
Hopefully this article has been useful for you to learn how to convert False to 0 in Python.