-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPS8.py
More file actions
59 lines (42 loc) · 1.65 KB
/
OOPS8.py
File metadata and controls
59 lines (42 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Employee:
var=8
no_of_leaves=15
def __init__(self,name,salary,role): # init function makes the class take argument
self.name=name
self.salary=salary
self.role=role
def printdetails(self): # self is meant as the object on which the code is written
return f"Name is {self.name}, Salary is {self.salary} Rs and role is {self.role}"
@classmethod #using class methods we can change a variable value in a function
def change_leaves(cls, newleaves): # cls is a class which has an instance of an object, it takes class not self
cls.no_of_leaves=newleaves
@classmethod
def from_str(cls,string):
# params=string.split("-")
# return cls(params[0],params[1],params[2])
return cls(*string.split("-"))
@staticmethod
def printgood(string):
print("This is good "+string)
class Player:
var=9
no_of_games=12
def __init__(self,name,game):
self.name=name
self.game=game
def printdetails(self):
return f"Name is {self.name}, Salary is {self.salary} Rs and role is {self.role}"
class CoolEmployee(Player, Employee):
# var=10
language="C#"
def printlanguage(self):
print(self.language)
ansh=Employee("Ansh",25000000,"CEO")
lewis=Employee("Lewis",20030020,"2nd CEO")
# vikk=CoolEmployee("vikk",3000202020220,"Gamer")
# vikk.printlanguage()
# det=vikk.printdetails()
# print(det)
vikk=CoolEmployee("vikk",["Football"]) # As vikk has two arguments it will go to the player class and print the var there
print(vikk.var)
Shaw=Player("Shaw",["Football"])