ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
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))
  1. A. 2 15 15 15 {'m': 15}
  2. B. 2 10 15 10 {}
  3. C. 2 15 15 10 {'m': 15}
  4. D. 2 10 15 10 {'m': 15}

Correct answer: D. 2 10 15 10 {'m': 15}

q.m += 5 reads the class attribute (10) and writes an instance attribute on q, leaving P.m at 10. vars(q) shows q's instance dict.

More Python Programming questions

Exams that ask this topic