Question 7
Back to Exercise
What is the output of the following Python program?
def combined():
yield from [1, 2]
yield from "ab"
yield from range(2)
print(list(combined()))
- A [[1, 2], 'ab', range(0, 2)]
- B [1, 2, 'ab', 0, 1]
- C [1, 2, 'a', 'b', 1, 2]
- D [1, 2, 'a', 'b', 0, 1] Correct
Correct Answer: Option D
yield from produces each item of the iterable separately, including each character of the string.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!