Mega Code Archive

 
Categories / Python Tutorial / Class
 

The property() built-in function can take up to four arguments

# Its signature is: property(fget=None, fset=None, fdel=None, doc=None) class MyClass(object):     def __init__(self, x):         assert isinstance(x, int), '"x" must be an integer!'         self.__x = ~x     def get_x(self):         return ~self.__x     x = property(get_x) inst = MyClass('foo') inst = MyClass(10) print 'inst.x =', inst.x inst.x = 20