-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut63.AccessSpecifiers&NameMangling.py
104 lines (60 loc) · 2.35 KB
/
tut63.AccessSpecifiers&NameMangling.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#....................................................................................................................
### if you have some data on Paper ###
#....................................................................................................................
# Public : accesible to all ....ghar ke baher kagaj chipkana...sabhi log dekh sakhenge
# Protected : sirf ghar wale dekhe kagaj ..ghar wale dekh sakhenge
# Private : room ke andar chikpayenge ...koi nahi dekhega othe than self
#...................................................................................................................
class Employee:
x=10 #default is public ........
_protec=12 #protected variable
__privt=21
l=10
y=50
def __init__(self,a,b,c,d):
self.name=a
self.std=b
self.city=c
self.salary=d
def showDetails(self):
print(f"name is {self.name}\n std is {self.std}\n city is {self.city}\n salary is {self.salary}\n")
@classmethod
def changeInstance(cls,d):
cls.x=d
@classmethod
def fromDash(cls,string):
return cls(*string.split("--"))
@classmethod
def fromEq(cls,string):
sp=string.split("=")
return cls(sp[0],sp[1],sp[2],sp[3])
@staticmethod
def printStatic():
print("print static plxz")
class EmployeeX:
z=100
def Wishing(self):
print("harry wishes you happy coding\n")
class EmployeeXY(Employee,EmployeeX):
def printAdd(self):
return self.l+self.z
def add(a,b):
print("sum is : ",a+b)
harry=EmployeeXY("harry",12,"vita",10000)
harry.showDetails()
larry=EmployeeXY.fromDash("larry--11--vita--20000")
print("larry's name is",larry.name)
jerry=EmployeeXY.fromEq("jerry=13=vita=30000")
print("jerry's salary is :",jerry.salary)
harry.x=100
print("intance value of x : ",harry.x)
print("class variable value of x: ",EmployeeXY.x)
harry.changeInstance(20)
print("changed value is :-",harry.x)
harry.printStatic()
harry.Wishing()
print("sum in class is ", harry.printAdd())
add(3,4)
print(harry._protec)
print(harry._Employee__privt) #name Mangling
#....................................................................................................................