Skip to content

Instantly share code, notes, and snippets.

@Deep18-03
Last active May 13, 2020 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deep18-03/0eec5d5ec1c95e8fac7f7cec8b1ff244 to your computer and use it in GitHub Desktop.
Save Deep18-03/0eec5d5ec1c95e8fac7f7cec8b1ff244 to your computer and use it in GitHub Desktop.
simple class method example
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