Home >>Python Built-in Functions >Python property() function
Python property() function is used to create property of a given class. If no arguments are given then it returns a base property attribute that doesn’t contain any getter, setter or deleter.
Syntax:property(fget, fset, fdel, doc)
Parameter | Description |
---|---|
fget | This parameter is used to get the value of attribute |
fset | This parameter is used to set the value of attribute |
fdel | This parameter is used to delete the attribute value |
doc | This parameter is a string that contains the documentation (docstring) for the attribute |
class Alphabet:
def __init__(self, value):
self._value = value
def getValue(self):
print('Getting value')
return self._value
def setValue(self, value):
print('Setting value to ' + value)
self._value = value
def delValue(self):
print('Deleting value')
del self._value
value = property(getValue, setValue, delValue, )
x = Alphabet('PHPTPOINT')
print(x.value)
x.value = 'Abhi'
del x.value