class Employee:
no_of_leaves = 8
def __init__(self, aname, asalary, arole):
self.name = aname
self.salary = asalary
self.role = arole
def printdetails(self):
return f"The Name is {self.name}. Salary is {self.salary} and role is {self.role}"
harry= Employee("harry", "230", "teacher")
harry.printdetails()
#this is you class Employee where we have set the properties using __init__
# def printdetails(self): is your method declaration. Here, You have the function that we are to run.
# this whole employee thingy is the class. class is like a blueprint of a house and object is like the physical house. Every time you call the class, and object is built. So, here our object is the output that we want to see.
output:
'The Name is harry. Salary is 230 and role is teacher'
No comments:
Post a Comment