what is a generator in python
On the surface generators in Python look like functions, but there is both a syntactic and a semantic difference. One distinguishing characteristic is the yield statements. The yield statement turns a functions into a generator. A generator is a function which returns a generator object.
, former Python Developer. Generators are iterators, but not all iterators are generators. An iterator is typically something that has a next method to get the next element from a stream. A generator is an iterator that is tied to a function. Regards, Python Developer. Views Â· View Upvotes.