LearnFrenzy
Sign in Take a free test

Tuples · Predict the Output · Question 12

Converting iterables with tuple() Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following Python program?

main.py
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links