ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
a = "abc"
b = "".join(["a", "b", "c"])
print(a == b, a is b or True, sorted(set(a + b)), a.find("c") == a.index("c"), "%s" % [a])
  1. A. True False ['a', 'b', 'c'] True ['abc']
  2. B. True True ['a', 'a', 'b', 'b', 'c', 'c'] True ['abc']
  3. C. True True ['a', 'b', 'c'] False ['abc']
  4. D. True True ['a', 'b', 'c'] True ['abc']

Correct answer: D. True True ['a', 'b', 'c'] True ['abc']

Equal strings compare equal regardless of identity, and `x or True` is always truthy. The set removes duplicate characters. find and index agree when the substring exists (they differ only for a missing one). %s formats the one-item list via str, which shows the string's repr inside.

More Python Programming questions

Exams that ask this topic