【发布时间】:2018-05-16 19:58:29
【问题描述】:
从 python 2.x -> python 3.x 转换时,我发现内置 max 函数的行为发生了这种变化。我没有发现它记录在任何关于迁移问题的标准位置。
https://eev.ee/blog/2016/07/31/python-faq-how-do-i-port-to-python-3/
http://python-future.org/compatible_idioms.html
我该如何解决这个问题?
Python 2.x:
In [1]: max([None, None, None])
In [2]:
Python 3.x:
In [3]: max([None, None, None])
---------------------------------------------------------------------------
TypeError
Traceback (most recent call last) <ipython-input-3-f82c85b9875c> in <module>()
----> 1 max([None, None, None])
TypeError: '>' not supported between instances of 'NoneType' and 'NoneType'
【问题讨论】:
-
我投票结束这个问题,因为它不是一个问题。
-
我回答了我自己的“问题”(见下文),为了帮助他人,应该明确鼓励这个问题。
-
@Shankari:是的,回答你自己的问题是允许的,但我仍然没有在这篇文章的“问题”部分看到任何看起来像问题的东西。
-
@Shankari 以某种方式提出问题,因为有人可能会在此处或在 Google 中输入该问题以找到答案。
标签: python python-3.x python-2.7