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])- A. True False ['a', 'b', 'c'] True ['abc']
- B. True True ['a', 'a', 'b', 'b', 'c', 'c'] True ['abc']
- C. True True ['a', 'b', 'c'] False ['abc']
- 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
- What is printed? python temps = {"mon": 30, "tue": 25, "wed": 35} hot = [d for d, t in temps.items() if t > 28] coolest = min(temps…
- What is printed? python s = "level" t = "".join(reversed(s)) u = s[::-1] print(s == t == u, t is s, list(reversed([1, 2])) == [2, 1]…
- What is printed? python marks = [72, 85, 64, 85, 90] print(marks.index(85), marks.count(85), sorted(marks)[len(marks) // 2]…
- What is printed? python inventory = {"pen": 3, "ink": 0} inventory["pad"] = inventory.get("pad", 0) + 5 inventory.update(ink=2)…
- What is printed? python def area(w, h=None): if h is None: h = w return w h print(area(3), area(3, 4), area(h=2, w=5), area([2, 6]))
- What is printed? python q = [1, 2, 3] stack = [1, 2, 3] print(q.pop(0), stack.pop(), q, stack, q + stack)