Python property()
Python property() class
The property() class in Python returns a property attribute.
Syntax
class property(fget=None, fset=None, fdel=None, doc=None)
Parameter
fget: This attribute is used for getting an attribute value.
fset : This parameter sets an attribute value.
fdel: It is a function for deleting an attribute value.
doc: This parameter creates a docstring for the attribute.
Return
This class returns a property attribute.
Example 1
# Python Program describing # the property() class class Function: def __init__(self, value): self._value = value # getting the values def getValue(self): print('Getting the value: ') return self._value # setting the values def setValue(self, value): print('Setting the value: ' + value) self._value = value # deleting the values def delValue(self): print('Deleting the value') del self._value value = property(getValue, setValue, delValue, ) # passing the value n = Function('HelloWorld') print(n.value) n.value = 'TAE' del n.value
Output
Getting the value: HelloWorld Setting the value: TAE Deleting the value