Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Attributes Annotations | Encapsulation
Object-Oriented Programming in Python
course content

Зміст курсу

Object-Oriented Programming in Python

Object-Oriented Programming in Python

1. Classes and Objects
2. Encapsulation
3. Inheritance
4. Polymorphism

Attributes Annotations

Using annotations starting with @ symbol is a special way to define properties.

  • Write @property to define get() method;
  • Write @attribute.setter to define the set() 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 the cat.age expression;

Сhoose the wrong option.

Виберіть правильну відповідь

Все було зрозуміло?

Секція 2. Розділ 3
We're sorry to hear that something went wrong. What happened?
some-alt