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 Programming Course & Exercises
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().
If you are a beginner, then I highly recommend this book.
Try the exercises below
- Add a variable age and create a getter and setter
- Why would you use getter and setter methods?
After completing these continue with the next exercise.