In Python 3.x, all non-zero numbers are mapped to "True" in Boolean contexts; however, in an equality statement, 1 behaves different from all the rest (see below). What's up with that? Why is 1 special among non-zero numbers?
>>> bool(1)
True
>>> bool(2)
True
>>> 1 and True
True
>>> 2 and True
True
>>> 1 == True
True
>>> 2 == True
False
Note that this is not explained by the difference between '==' and 'is':
>>> one = 1
>>> one is True
False
>>> two = 2
>>> two is True
False
question from:
https://stackoverflow.com/questions/65888057/python-numbers-in-boolean-contexts 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…