Last active
May 14, 2020 19:20
-
-
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
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=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