To convert an integer to boolean in python, one can use the bool() function, example:
>>> n = 1>>> bool(n)True>>> n = 0>>> bool(n)False
Note that if the number is not 0, bool() always returns True:
>>> n = 9>>> bool(n)True>>> n = -1>>> bool(n)True
References
| Links | Site |
|---|---|
| Python bool() | programiz.com |
| bool(): Convert to Boolean | infohost.nmt.edu |
| Is False == 0 and True == 1 in Python an implementation detail or is it guaranteed by the language? | stackoverflow |
