-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunderscore_example.py
More file actions
44 lines (34 loc) · 811 Bytes
/
underscore_example.py
File metadata and controls
44 lines (34 loc) · 811 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
33
34
35
36
37
38
39
40
41
42
43
44
# The underscore
# Often ignored but there are multiple usecases
# _single
# __Double
# __Before
# After__
# __Both__
from underscore_example1 import *
# Skipping
for _ in range(5):
print('Hello')
# Before(Single)
# Internal use only , called a weak private
p = Person()
p.set_name('Bryan')
print(f'Weak private {p._name}')
p._name = 'NOOOOOOOOO' # should never do this
print(f'Weak Private {p._name}')
# Before (Double)
# Internal use only, avoid conflict in subclass
# and tells python to rewrite the name (Mangling)
p = Person()
p.work()
# p.__think()
# c = Child()
# c.test_double()
# After (any)
# Helps to avoid naming conflicts with key words
class_ = Person()
print(dir(class_))
# Before and after
# Considered special to python, like the init and main function
p = Person()
p.__call__()