Skip to content

Instantly share code, notes, and snippets.

@Deep18-03
Last active May 14, 2020 19:20
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/e90d11ab678afc613636ef987738aef8 to your computer and use it in GitHub Desktop.
Save Deep18-03/e90d11ab678afc613636ef987738aef8 to your computer and use it in GitHub Desktop.
This class method is used when you have to take value from wordpad in form of deep-2323-slalr
class Employee:
no_of_leaves=9
def __init__(self,aname,asalary,arole):
self.name=aname
self.salary=asalary
self.role=arole
def printable(self):
return f"Name of the employeer is {self.name} and his work as a {self.role} and having salary {self.salary}"
@classmethod
def change_leaves(cls,new_leaves):
cls.no_of_leaves=new_leaves
@classmethod
def fromstring(cls,string):
#params=string.split("-")
#return cls(params[0],params[1],params[2]) This will give list
return cls(*string.split("-")) #single line code
Carry=Employee("Carry",78000,"Technician")
Danny=Employee("Danny",887878,"Programmer")
Manny=Employee.fromstring("Manny-5677-Non programmer") #instance variable
print(Carry.printable())
print(Danny.printable())
Employee.change_leaves(7)
print(Manny.printable())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment