ProgrammingModerateAccenture · Capgemini pattern
What is printed?
What is printed?
a = {1, 2, 3, 4}
b = {3, 4, 5}
print(a - b, b - a, len(a | b), a & b == {4, 3})- A. {1, 2} {5} 5 True
- B. {1, 2, 5} {5} 5 True
- C. {1, 2} {5} 7 True
- D. {1, 2} {5} 5 False
Correct answer: A. {1, 2} {5} 5 True
a - b keeps elements of a not in b: {1, 2}; b - a is {5}. The union {1, 2, 3, 4, 5} has 5 elements. a & b is {3, 4}, and sets compare by contents regardless of order, so == {4, 3} is True. {1, 2, 5} would be the symmetric difference a ^ b.
More Python Programming questions
- What is printed? python print(" ".join(i ch for i, ch in enumerate("xyz", 1)), list(enumerate("ab"))[-1])
- What is printed? python nums = list(range(10)) print(nums[8:2:-2], nums[-3:], nums[2:8:-1])
- What is printed? python print(min([3, -4, 2], key=lambda v: v v), max({"a": 3, "b": 1}), max("abc", "b", key=len))
- What is printed? python class Box: def len(self): return 0 b = Box() print(bool(b), "yes" if b else "no", len([b, b]))
- What is printed? python a = [3, 1, 4, 1, 5] a.insert(-1, 9) print(a, a.index(1), a.pop(), a.count(1))
- What is printed? python def g(): print("start", end=" ") yield 1 print("mid", end=" ") yield 2 it = g() print("made", end=" ")…