Confused with python lists: are they or are they not iterators?

前端 未结 4 1689
深忆病人
深忆病人 2020-12-02 08:25

I am studying Alex Marteli\'s Python in a Nutshell and the book suggests that any object that has a next() method is (or at least can be used as) an ite

4条回答
  •  时光取名叫无心
    2020-12-02 09:11

    They are iterable, but they are not iterators. They can be passed to iter() to get an iterator for them either implicitly (e.g. via for) or explicitly, but they are not iterators in and of themselves.

提交回复
热议问题