小编Ism*_* Vc的帖子

为什么{} | [] |()| str | set | etc.> n等于python2.x中的True?

我在尝试比较时注意到了这一点:

if len(sys.argv) >= 2:
    pass
Run Code Online (Sandbox Code Playgroud)

但我做到了这一点仍然是真的(花了我一些时间来找到这个bug.):

if sys.argv >= 2: # This is True!!!
    pass
Run Code Online (Sandbox Code Playgroud)

以下是一些例子:

>>> {} > 2
True
>>> [] > 2
True
>>> () > 2
True
>>> set > 2
True
>>> str > 2
True
>>> enumerate > 2
True
>>> __builtins__ > 2
True
>>> class test:
...     pass
... 
>>> test
<class __main__.test at 0xb751417c>
>>> test > 2
True
Run Code Online (Sandbox Code Playgroud)

在python3.x中它会导致TypeError.

python comparison python-2.7

1
推荐指数
1
解决办法
54
查看次数

标签 统计

comparison ×1

python ×1

python-2.7 ×1