yield from () Was: Re: weirdness with list()

Chris Angelico rosuav at gmail.com
Mon Mar 1 14:16:05 EST 2021


On Tue, Mar 2, 2021 at 5:51 AM Alan Gauld via Python-list
<python-list at python.org> wrote:
>
> On 28/02/2021 00:17, Cameron Simpson wrote:
>
> > BUT... It also has a __iter__ value, which like any Box iterates over
> > the subboxes. For MDAT that is implemented like this:
> >
> >     def __iter__(self):
> >         yield from ()
>
> Sorry, a bit OT but I'm curious. I haven't seen
> this before:
>
> yield from ()
>
> What is it doing?
> What do the () represent in this context?
>

It's yielding all the elements in an empty tuple. Which is none of
them, meaning that - for this simple example - iterating over the
object will produce zero results.

ChrisA


More information about the Python-list mailing list