Now you know what getter and setter methods are and where they come from. These methods allow access and mutation of attributes while avoiding API changes. However, they’re not so popular in Python because of the existence of properties. Properties allow you to add behavior to your attributes while avoiding breaking changes in your APIs.
Even though properties are the Pythonic way to replace traditional getters and setters, properties can have some practical drawbacks that you can overcome with getters and setters.
In this video course, you’ve learned how to:
- Write getter and setter methods in Python
- Use Python properties to replace getter and setter methods
- Use Python tools, like descriptors, to replace getters and setters
- Decide on when setter and getter methods can be the right tool for the job
To learn more about the concepts in this course, check out:
- Managing Attributes With Python’s
- Using Python Class Constructors
- Python Descriptors: An Introduction
- Inheritance and Composition: A Python OOP Guide
- Raising and Handling Python Exceptions
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.