How to convert number 1 to a Boolean in python
问题 I have seen similar questions asked, but none have answered my question. I am relatively new to python, and have no idea what i'm doing. 回答1: Use: >>> bool(1) True >>> bool(0) False >>> int(bool(1)) 1 >>> int(bool(0)) 0 Can convert back too. 回答2: Unless you don't want to explicitly use Boolean type variable you don't need to. Python accepts it as True in many expression: print(True == 1) print(False == 0) Out: True True In other cases you can use bool(1) of course. print(bool(1)) print(bool(0