What does it mean to “consume” in Python? In an iterator?

前端 未结 6 718
既然无缘
既然无缘 2020-12-11 01:45

I have been working in Python for a few months now, and it has occurred to me that I often overlook vocabulary that escapes me at first glance, instead trying to get the gis

6条回答
  •  醉梦人生
    2020-12-11 02:33

    Does "consuming" do different things in different Pythonic contexts?

    No, "consuming" always does the same thing.

    What happens to data when it is consumed, such as in iter()?

    It is no longer available from the place you got it.

    When a variable is assigned to an iterator's result-- the allegedly consumed piece of data-- does it no longer belong to the iterator?

    Correct. As soon as the iterator produces the data, the data no longer belongs to the iterator.

    Can you consume more than one value from an iterator object in a single call to the iterator?

    Usually, no. However, you can write a custom iterator that produces more than one of its values at a time.

提交回复
热议问题