Getter and setter

A class can have one more variables (sometimes called properties). When you create objects each of those objects have unique values for those variables.

Class variables need not be set directly: they can be set using class methods. This is the object orientated way and helps you avoid mistakes.

Related course: Complete Python Bootcamp: Go from zero to hero in Python


We create a class with a properties. From that class we create several objects.

These objects do not have the property (job) set. To set it, we could set it directly but that’s a bad practice. Instead we create two methods: getJob() and setJob().

Two objects are created, both of them have unique values for the property job:
getter setter

Study drill

Try the exercises below

After completing these continue with the next exercise.