Classes in Python

A class is a wrapping of data member and  member function inside a single unit.

Lets take an example of a Interest class in which we have members, principal, rate and time. We have member function as SimpleIntrest.

class Interest():
rate=3.5
def __init__(self,p,t):
#Data Members
self.principal=p
self.rate=self.rate
self.time=t
self.si=self.principal*self.rate*self.time/100
pass
#Memeber Function
def SimpleIntrest(self):
print(self.si)
def Amount(self):
print(self.principal+self.si)
pass

Call the function from the object obj.

obj=Intrest(1000,2)
obj.SimpleIntrest()
obj.Amount()

obj1=Intrest(2000,2)
obj1.SimpleIntrest()

 

Leave a Reply