ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
a = {1, 2}
b = a
a |= {3}
c = frozenset(a)
a = a | {4}
print(b, c, a, type(c | {9}).__name__)- A. {1, 2} frozenset({1, 2, 3}) {1, 2, 3, 4} frozenset
- B. {1, 2, 3, 4} frozenset({1, 2, 3}) {1, 2, 3, 4} set
- C. {1, 2, 3} frozenset({1, 2, 3}) {1, 2, 3, 4} frozenset
- D. {1, 2, 3} frozenset({1, 2, 3}) {1, 2, 3, 4} set
Correct answer: C. {1, 2, 3} frozenset({1, 2, 3}) {1, 2, 3, 4} frozenset
|= updates the set in place (b sees 3), while a | {4} builds a new set and rebinds only a. Binary operations on a frozenset return the type of the left operand, a frozenset.
More Python Programming questions
- 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)
- What is printed? python class P: pass p = P() p.n = 1 p.n += 1 P.m = 10 q = P() q.m += 5 print(p.n, P.m, q.m, p.m, vars(q))