ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE
What does the following Python 3 code print? a, b = set([11,9,12,1,11]), set([3,11,11,5,7,4]) print(sorted(a ^ b), len(a - b))
- A. [1, 3, 4, 5, 7, 9, 12] 4
- B. [1, 9, 12] 7
- C. [1, 3, 4, 5, 7, 9, 11, 12] 3
- D. [1, 3, 4, 5, 7, 9, 12] 3
Correct answer: D. [1, 3, 4, 5, 7, 9, 12] 3
^ keeps elements in exactly one set (symmetric difference); a − b keeps those only in a. Duplicates collapse when the sets are built. Output: [1, 3, 4, 5, 7, 9, 12] 3.
More Python Programming questions
- What does the following Python 3 code print? def mk(): c = 0 def inc(): nonlocal c c += 4 return c return inc a, b = mk(), mk() for in…
- What does the following Python 3 code print? a, b, c = 30, 3, 39 print((a << b) ^ c, a & ~c, (a | c) >> b)
- What does the following Python 3 code print? def f(): try: return 3 finally: print("f", end=" ") x = f() + 10 print(x)
- What does the following Python 3 code print? a, b = [1,6,5,3], [8,3,5,8] print(list(map(lambda p: p[0] p[1], zip(a, b))), len(list(zip(a…
- What is printed? python def k(a, b=(1, 2)): return b print(k(1) is k(2))
- What is printed? python class Box: def init(self, items=[]): self.items = items b1 = Box() b2 = Box() b1.items.append(1) print(b2.items)