What exactly are iterator, iterable, and iteration?

前端 未结 13 1639
遥遥无期
遥遥无期 2020-11-21 05:27

What is the most basic definition of \"iterable\", \"iterator\" and \"iteration\" in Python?

I have read multiple definitions but I am unable to identify the exact m

13条回答
  •  迷失自我
    2020-11-21 06:04

    I don't think that you can get it much simpler than the documentation, however I'll try:

    • Iterable is something that can be iterated over. In practice it usually means a sequence e.g. something that has a beginning and an end and some way to go through all the items in it.
    • You can think Iterator as a helper pseudo-method (or pseudo-attribute) that gives (or holds) the next (or first) item in the iterable. (In practice it is just an object that defines the method next())

    • Iteration is probably best explained by the Merriam-Webster definition of the word :

    b : the repetition of a sequence of computer instructions a specified number of times or until a condition is met — compare recursion

提交回复
热议问题