Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 24354

Real Python: Getters and Setters in Python

$
0
0

If you come from a language like Java or C++, then you’re probably used to writing getter and setter methods for every attribute in your classes. These methods allow you to access and mutate private attributes while maintaining encapsulation. In Python, you’ll typically expose attributes as part of your public API and use properties when you need attributes with functional behavior.

Even though properties are the Pythonic way to go, they can have some practical drawbacks. Because of this, you’ll find some situations where getters and setters are preferable over properties.

In this video course, you’ll:

  • Write getter and setter methods in your classes
  • Replace getter and setter methods with properties
  • Explore other tools to replace getter and setter methods in Python
  • Decide when setter and getter methods can be the right tool for the job

To get the most out of this course, you should be familiar with Python object-oriented programming. It’ll also be a plus if you have basic knowledge of Python properties and descriptors.


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]


Viewing all articles
Browse latest Browse all 24354

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>