What is the output of the following Python code snippet?
def g():
for i in range(3):
yield i
print(list(g()))
for i in range(3):
yield i
print(list(g()))
Correct answer
A. [0, 1, 2]
11 views
A. [0, 1, 2]
11 views
A generator function can be consumed by list().
Asked in: Python Interview Advanced
https://docs.python.org/3/library/index.htmlNot sure why the answer is A? Ask here and get an explanation.