Last active
May 13, 2020 13:56
-
-
Save Deep18-03/0eec5d5ec1c95e8fac7f7cec8b1ff244 to your computer and use it in GitHub Desktop.
simple class method example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee: | |
no_of_leaves=8 #class variable | |
def __init__(self,aname,asalary,arole): | |
self.name=aname | |
self.salary=asalary | |
self.role=arole | |
def printable(self): | |
return f"Name is {self.name} and salary is {self.salary} and role is {self.role}" | |
@classmethod | |
def change_leaves(cls,new_leaves): | |
"""This function is used to changenthe class variable taking one parameter""" | |
cls.no_of_leaves=new_leaves | |
carry=Employee("Carry",70000,"Engieneer") #instance variable | |
cheery=Employee("Cherry",90000,"Technician") #instance variable | |
print(carry.printable()) | |
Employee.change_leaves(4) | |
print(carry.no_of_leaves) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment