-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path64_access_modifier.py
More file actions
32 lines (23 loc) · 964 Bytes
/
Copy path64_access_modifier.py
File metadata and controls
32 lines (23 loc) · 964 Bytes
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
class football:
networth = 10000 # Public
_salary = 100 # Protected
__blackmoney = 1000 # Private
def printdetails(self):
print("\nNetworth (using public method) :", self.networth)
print("Salary (using public method) :", self._salary)
print("Blackmoney (using public method) :", self.__blackmoney)
class premier(football):
# protected variable can be accessed by derived class
sal = football._salary
# blk=football.__blackmoney # private cannot getting accessed by derived class
pass
f = premier()
print("\nNetworth (Outside) :", f.networth)
print("Salary (Outside) :", f._salary)
# print("Blackmoney :",f.__blackmoney) # we cannot access private varaible as it is
f.printdetails()
print("\nBlackmoney (Name Mangling) :", f._football__blackmoney)
"""
- We can access private members either by using a public method or
we can directly access them by "name mangling"
"""