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

Conteúdo do Curso

Object-Oriented Programming in Python

Object-Oriented Programming in Python

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

Get and Set

Getter and setter are methods for non-direct access to the attributes:

  • get() (getter) returns the value of the private attribute;
  • set() (setter) sets the value.

These methods are called properties.

You can implement them by defining two additional methods:

Note

We added data validation inside the set_age() method. Only the correct integer value can be assigned to the attribute.

Tudo estava claro?

Seção 2. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt