Question 12
Back to Exercise
What is the output of the following Python program?
print(tuple("abc"), tuple([1, 2]), tuple({3: "a", 4: "b"}), tuple(range(3)))
- A ('abc',) (1, 2) (3, 4) (0, 1, 2)
- B ('a', 'b', 'c') (1, 2) (3, 4) (0, 1, 2) Correct
- C ('a', 'b', 'c') (1, 2) ('a', 'b') (0, 1, 2)
- D ('a', 'b', 'c') ([1, 2],) ((3, 'a'), (4, 'b')) (0, 1, 2)
Correct Answer: Option B
tuple() iterates its argument: a string gives characters, a dict gives its keys.
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!