-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPS10.py
More file actions
51 lines (38 loc) · 1.58 KB
/
OOPS10.py
File metadata and controls
51 lines (38 loc) · 1.58 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
class Employee:
var=8
no_of_leaves=15 # this is public variable
_protected=1 # this is protected variable
__private=22 # this is private variable
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)
emp=Employee("Ansh",2948,"CEo")
print(emp._protected) # this will print as it is protected
print(emp._Employee__private) # as it is private, have to add _class name in front