Why does … == True return False in Python 3?

后端 未结 4 1619
自闭症患者
自闭症患者 2021-02-08 01:53

I am learning python, but I\'m a bit confused by the following result.

In [41]: 1 == True
Out[41]: True

In [42]: if(1):
    ...:     print(\'111\')
    ...:             


        
4条回答
  •  半阙折子戏
    2021-02-08 02:13

    I believe it's 1 == True here is that's weird, not that ... != True.

    1 equals with True because in Python booleans are subclass of integers (because of PEP-285). See yourself:

    >>> issubclass(bool, int)
    True
    

提交回复
热议问题