ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
s = {1, 2, 3}
t = {3, 4}
print(s | t, s & t, s - t, s ^ t, s >= {1, 2})- A. {1, 2, 3, 4} {3} {1, 2, 4} {1, 2, 4} True
- B. {1, 2, 3, 3, 4} {3} {1, 2} {4} True
- C. {1, 2, 3, 4} {3} {1, 2} {1, 2, 4} True
- D. {1, 2, 3, 4} {3} {1, 2} {1, 2, 4} False
Correct answer: C. {1, 2, 3, 4} {3} {1, 2} {1, 2, 4} True
| is union, & intersection, - difference (in s but not t), ^ symmetric difference (in exactly one), and >= tests superset.
More Python Programming questions
- What is printed? python a = {1, 2} b = a a |= {3} c = frozenset(a) a = a | {4} print(b, c, a, type(c | {9}).name)
- What is printed? python s = set() s.add((1, 2)) s.add((2, 1)) try: s.add([1]) except TypeError: s.add(frozenset([1]))…
- What is printed? python d = {"a": 1, "b": 2, "c": 3} del d["a"] d["a"] = 4 d.pop("b") d["b"] = 5 print(list(d.items()), next(iter(d))…
- What is printed? python class Key: def init(self, v): self.v = v def hash(self): return hash(self.v) def eq(self, o): return self.v == o.v…
- What is printed? python d = dict.fromkeys(range(3), 0) for k in d: d[k] += k e = {k: [] for k in "ab"} e["a"].append(1) f =…
- What is printed? python x = None print(x is None, x == None, bool(None), type(None).name, None is not False)