What is the output of the following? def gen(): yield from range(3) print(list(gen()))

Python Developer Medium

Python Developer — Medium

What is the output of the following? def gen(): yield from range(3) print(list(gen()))

Key points

  • yield from simplifies generator code by delegating to another iterable
  • The list() function is used to convert the generator output to a list
  • The range(3) generates values 0, 1, 2

Ready to go further?

Related questions