yield from () Was: Re: weirdness with list()
Peter Otten
__peter__ at web.de
Mon Mar 1 15:48:57 EST 2021
On 01/03/2021 00:47, Alan Gauld via Python-list 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?
The 0-tuple ;)
yield from x
is syntactic sugar for
for item in x:
yield item
Instead of () you can use any empty iterable.
If x is empty nothing is ever yielded.
More information about the Python-list
mailing list