- 论坛徽章:
- 0
|
ietr is a build-in function
iter(o[, sentinel])
Return an iterator object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, o must be a collection object which supports the iteration protocol (the __iter__() method), or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0). If it does not support either of those protocols, TypeError is raised. If the second argument, sentinel, is given, then o must be a callable object. The iterator created in this case will call o with no arguments for each call to its next() method; if the value returned is equal to sentinel, StopIteration will be raised, otherwise the value will be returned.
也就是说
i = iter(x)
之后,因为x有__getitem__, i就是iterable的了
[ 本帖最后由 pastebt 于 2009-5-30 04:43 编辑 ] |
|