-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifiers.py
More file actions
16 lines (13 loc) · 1.06 KB
/
Copy pathmodifiers.py
File metadata and controls
16 lines (13 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# python do not have public private protected keywords but are discused
# public - members are accessible from outside the class. private - members cannot be accessed (or viewed) from outside the class. protected - members cannot be accessed from outside the class, however, they can be accessed in inherited classes.
# access modifiers are used to restrict the access of the class member variable and methods from outside the class
class emp:
def __init__(self):
self.__name="danish"
a=emp()
# print(a.__name) # so it is a private var so cannot be directly accessed
print(a._emp__name) # private var can be accessed with this code
print(a.__dir__()) # print all the built in methods
# when we make a variable is prefix with __ then it is a weak indication of private variable but we can access it
#In name mangling process any identifier with two leading underscore and one trailing underscore is textually replaced with _classname__identifier where classname is the name of the current class
# but with inheritence we can access the base class private methods directly