Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 30)
30.
Consider the following Python code:
def my_generator():
    yield 1
    yield 2
    yield 3

result = list(my_generator())
print(result)
What will be the output of this code?
[1, 2, 3]
(1, 2, 3)
{1, 2, 3}
This code will result in an error.
Answer: Option
Explanation:
The generator function is converted to a list using the list() constructor.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.