Hello friends!!!!!

Property decorator

PYTHON

11/11/20241 min read

'''

"@property" is a decorator on any method of the class to use the method as a property.

'''

#example :

class avg:

def __init__(self,mat,phy,che):

self.mat = mat

self.phy = phy

self.che = che

@property

def average(self):

return (self.mat + self.phy + self.che) / 3

a = avg(98,93,89)

print(a.average)

a.che = 97

print(a.average)

Output:

93.33333333333333

96.0

=== Code Execution Successful ===