为什么元组大于类似的列表? [英] Why a tuple is greater than a similar list?
本文介绍了为什么元组大于类似的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下一个元组比列表大有什么理由吗?
<预><代码>>>>t = ( 1, 2, 3 )>>>l = [ 1, 2, 3 ]>>>≥升真的>>><升错误的 解决方案
在 Python 2 中,任何元组总是比任何列表都大——这正是它在语言中定义的方式.
在 Python 3 中,这是固定的,因此比较元组和列表会给出 TypeError: unorderable types: tuple() >list()
.
Is there any reason why the next tuple is greater then the list?
>>> t = ( 1, 2, 3 )
>>> l = [ 1, 2, 3 ]
>>> t > l
True
>>> t < l
False
解决方案
In Python 2, any tuple is always compared as greater than any list - that's just the way it is defined in the language.
In Python 3, this is fixed, so that comparing tuples and lists gives TypeError: unorderable types: tuple() > list()
.
这篇关于为什么元组大于类似的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文