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")
  1. A. 10
  2. B. 5
  3. C. AttributeError
  4. 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

Exams that ask this topic