Python property() class
The property() class in Python returns a property attribute.
Syntax
1 2 3 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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
1 2 3 4 5 6 |
Getting the value: HelloWorld Setting the value: TAE Deleting the value |