What is Python's property decorator?
Answer
The @property decorator allows a method to be accessed like an attribute, implementing getter/setter/deleter logic. Define a getter: @property def full_name(self): return f"{self.first} {self.last}" — access as person.full_name (no parentheses). Define a setter: @full_name.setter def full_name(self, value): self.first, self.last = value.split() — assign as person.full_name = "Alice Smith". Define a deleter: @full_name.deleter def full_name(self): del self.first; del self.last. Properties enforce encapsulation while keeping a clean attribute-access API. Use them for computed attributes, validation on assignment, and lazy-loading. Unlike Java's explicit getters/setters, Python properties let you start with a public attribute and later add logic without changing the API.
Previous
What are Python's class and static methods?
Next
What is Python's __str__ and __repr__ methods?