Teaching the "range" function in Python 3
Steve D'Aprano
steve+python at pearwood.info
Fri Jun 30 12:03:03 EDT 2017
On Fri, 30 Jun 2017 09:17 am, Stefan Ram wrote:
>>>> b = a.__iter__()
Don't do that.
Dunder ("Double UNDERscore") methods like __iter__ should only be called by the
Python interpreter, not by the programmer. The right way to create an iterator
is to call the built-in function iter:
b = iter(a)
The iter() function may call a.__iter__ (technically, it calls type(a).__iter__
instead) but it may also do other things, which you miss out on if you call
__iter__ directly.
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list