ProgrammingHardAccenture pattern
What is printed?
What is printed?
class R:
@property
def x(self):
return 5
r = R()
try:
r.x = 10
except AttributeError:
print("AttributeError")- A. 10
- B. 5
- C. AttributeError
- D. None
Correct answer: C. AttributeError
A property defined with only a getter (no @x.setter) has no __set__ behavior enabled, so assigning to it raises AttributeError ("can't set attribute").
More Python Programming questions
- What is printed? python try: raise TypeError("t") except (ValueError, TypeError) as e: print("caught", type(e).name)
- What is printed? python def f(): return 1, 2, 3 a, b, c = f() print(a, b, c) x = f() print(type(x), x)
- What is printed? python d = {"a": 1, "b": 2} print({v: k for k, v in d.items()})
- What is printed? python s1 = {1, 2, 3} s2 = {2, 3, 4} print(s1 - s2, s1 | s2, s1 & s2)
- What is printed? python print(all([1, 2, 3]), all([1, 0, 3]), any([0, 0, 0]), any([0, 1, 0]))
- What is printed? python x = None print(x or "default") y = 0 print(y or "default") z = "" print(z or "fallback")