You can convert a 1
to its boolean opposite (and vice versa) using int(not bool(n))
. This converts n
to a boolean value using bool()
, uses the not
keyword to get the boolean opposite of this value, and then converts this value to an integer with int()
.
print(
int(not bool(1)), # 0
int(not bool(0)), # 1
)