Python evaluates 0 as False

后端 未结 5 2129
旧时难觅i
旧时难觅i 2020-12-01 23:52

In the Python console:

>>> a = 0
>>> if a:
...   print \"L\"
... 
>>> a = 1
>>> if a:
...   print \"L\"
... 
L
>>&g         


        
5条回答
  •  心在旅途
    2020-12-02 00:34

    0 is a falsy value in python

    Falsy values: from (2.7) documentation:

    zero of any numeric type, for example, 0, 0L, 0.0, 0j.

提交回复
热议问题