Course Content
Object-Oriented Programming in Python
Attributes Annotations
Using annotations starting with @
symbol is a special way to define properties.
- Write
@property
to defineget()
method; - Write
@attribute.setter
to define theset()
method for the attribute.
We need to do that to explain to Python what these methods are going to be used for.
Note
- First, define getter
@property
and after that – setter@attribute.setter
; - Both methods have the same name, that is equal to the attribute name;
- Now, to access the private attribute
__age
outside the class, you can use thecat.age
expression;
Сhoose the wrong option.
Select the correct answer
Section 2.
Chapter 3