Home Tutorials Python OOP Concepts Property Decorator
Property Decorator

Property Decorator


36. Property Decorator

The @property decorator lets a method be accessed like an attribute while still controlling internal logic. It is a common Pythonic way to implement controlled access in encapsulation.

Syntax

@property
def name(self):
    return self._name

Example

class Student:
    def __init__(self, marks):
        self._marks = marks
        
    @property
    def marks(self):
        return self._marks

s = Student(95)
print(s.marks)

Output

95
Example

🏋️ Test Yourself With Exercises

Take our quiz on Property Decorator to test your knowledge.

Browse Quizzes »