所以这一直困扰着我,我无法在网上找到任何关于它的信息.有人可以在python中解释这个行为吗?为什么它返回True而不是抛出异常?谢谢
In [1]: 1 < [1, 2, 3]
Out[1]: True
Run Code Online (Sandbox Code Playgroud)
它确实抛出异常 - 无论如何,这些天:
$ python3
Python 3.3.0 (default, Apr 17 2013, 13:40:43)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 < [1,2,3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < list()
Run Code Online (Sandbox Code Playgroud)
Python过去常常让比较像这样通过,因为有时候能够在异构容器中自动排序所有东西都很方便,但这导致了更多的错误而不是方便,所以它在Python 3中修复了.
| 归档时间: |
|
| 查看次数: |
629 次 |
| 最近记录: |