编程语言
首页 > 编程语言> > Python:为什么不将“next()”称为“__next __()”

Python:为什么不将“next()”称为“__next __()”

作者:互联网

我正在使用Python 2.7.

按照惯例,内置方法如__iter __,__ init__,_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _为什么next()函数没有这个?

它与其他内置函数一起使用:https://docs.python.org/2/library/functions.html,这似乎不是一个非常一致的约定.

解决方法:

内置函数没有__,因为没有内置函数.您使用特殊方法(如__str__)混淆了内置函数(如str).

现在,内置下一个调用的特殊方法在Python 2.7中也被称为下一个,但该命名被认为是一个意外,并在Python 3中更改为__next__.

标签:python,naming-conventions
来源: https://codeday.me/bug/20190716/1477226.html