A property is a special type of class member that provides functionality that’s somewhere in between regular attributes and methods. Properties allow you to modify the implementation of instance attributes without changing the public API of the class. Being able to keep your APIs unchanged helps you avoid breaking code your users wrote on top of older versions of your classes.
Properties are the Pythonic way to create managed attributes in your classes. They have several use cases in real-world programming, making them a great addition to your skill set as a Python developer.
In this video course, you learned how to:
- Create managed attributes with Python’s
property()
- Perform lazy attribute evaluation and provide computed attributes
- Avoid setter and getter methods with properties
- Create read-only, read-write, and write-only attributes
- Create consistent and backwards-compatible APIs for your classes
If you’d like to learn more about the concepts covered in this course, then check out:
property()
- Python documentation- Properties - Python documentation
raise
- Python documentation- Logging in Python - Real Python tutorial
- Primer on Python Decorators - Real Python tutorial
- Write More Pythonic Code - Real Python learning path
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.