Skip to content

Latest commit

 

History

History
25 lines (23 loc) · 713 Bytes

File metadata and controls

25 lines (23 loc) · 713 Bytes

@Property

Definition

  • JAVA can hide variables from outside using private variables
  • like this, python can protect variables using property decorator
  • When assigning value to property variable, it needs to go through setter class.
class C(object):
            @property
            def x(self):
                "I am the 'x' property."
                return self._x
            @x.setter
            def x(self, value):
                "some expressions here"              
                self._x = value
            @x.deleter
            def x(self):
                del self._x

# How to Use
myclass = C()
myclass.x = 3 # setter called
print x       # property called