ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(eval("[i for i in range(3)]"), [x for x in "ab"] * 2, list(map(str.upper, "ab")), {*"aba"} == {"a", "b"})
  1. A. [0, 1, 2] ['a', 'b', 'a', 'b'] ['A', 'B'] True
  2. B. [0, 1, 2] ['aa', 'bb'] ['A', 'B'] True
  3. C. [0, 1, 2] ['a', 'b', 'a', 'b'] ['AB'] True
  4. D. [0, 1, 2] ['a', 'b', 'a', 'b'] ['A', 'B'] False

Correct answer: A. [0, 1, 2] ['a', 'b', 'a', 'b'] ['A', 'B'] True

Repeating a list concatenates copies of it; str.upper is an unbound method usable with map, applied to each character; {*'aba'} unpacks the string into a set of distinct characters.

More Python Programming questions

Exams that ask this topic