Python · OOP: Properties, Methods & Data Classes

You expose a public attribute obj.temp and ship it. Later you need to reject negative values on write. Why is starting with @property from day one the safer call?

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in OOP: Properties, Methods & Data Classes

What does this print? ``` class C: @property def area(self): return self.w * self.h c = C(); c.w, c.h = 3, 4 print(c.area) print(c.area()) ```
A class has @property def x with only a getter. What happens at obj.x = 5?
What does this print? ``` class A: @staticmethod def add(a, b): return a + b print(A.add(2, 3)) print(A().add(2, 3)) ```
What is printed? ``` class A: @classmethod def who(cls): return cls.__name__ class B(A): pass print(A.who(), B.who()) ```
You want Date.from_string("2026-06-27") to build and return a Date instance (an alternative constructor). Which method kind, and what's the key line in the body?
self / cls / nothing: which implicit first parameter does each receive — an instance method, a @classmethod, and a @staticmethod?

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play