Apr-08-2023, 09:51 PM
(This post was last modified: Apr-08-2023, 09:51 PM by Gribouillis.)
(Apr-08-2023, 07:30 PM)quazirfan Wrote: Does x is e or x == e for e in y return a generator expression which is also an iterable?
From a syntactic point of view
(x is e or x == e for e in y)is a "generator expression". Upon execution, this expression returns a Python object which type is "generator object". All generator objects are "iterable", which means that by applying the iter() function to these objects, it returns an "iterator".
>>> from collections.abc import Iterable, Iterator >>> g = (x is e or x == e for e in y) >>> g <generator object <genexpr> at 0x7f10b26bac70> >>> isinstance(g, Iterable) True >>> isinstance(iter(g), Iterator) TrueNote that "Iterable" and "Iterator" are interfaces (or abstract classes) rather than actual types.