【发布时间】:2021-09-09 14:12:47
【问题描述】:
我正在学习 enumerate()。一边学习,一边使用,
help(enumerate)
Help on class enumerate in module builtins:
class enumerate(object)
| enumerate(iterable, start=0)
|
| Return an enumerate object.
|
| iterable
| an object supporting iteration
|
| The enumerate object yields pairs containing a count (from start, which
| defaults to zero) and a value yielded by the iterable argument.
|
| enumerate is useful for obtaining an indexed list:
| (0, seq[0]), (1, seq[1]), (2, seq[2]), …
|
| Methods defined here:
|
| getattribute(self, name, /)
| Return getattr(self, name).
|
| iter(self, /)
| Implement iter(self).
|
| next(self, /)
| Implement next(self).
|
| reduce(…)
| Return state information for pickling.
Static methods defined here:
new(*args, **kwargs) from builtins.type
Create and return a new object. See help(type) for accurate signature.
即使我给了,
enumerate
<class ‘enumerate’>
但是,当我查看python官网的文档时,www.python.org为enumerate()
这表明 enumerate() 是一个违反 help() 显示信息的函数。
我不知道 enumerate() 是一个类还是一个函数。请任何人帮助我解决这个问题...
顺便说一句,我有 python 3.8.3。我什至签入了 python 3.6 和 3.7.10。
【问题讨论】:
-
enumerate是可调用的。类和函数都是可调用的。本文有更多信息:Is it a class or a function? It's a callable!