-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference.py
More file actions
58 lines (46 loc) · 924 Bytes
/
reference.py
File metadata and controls
58 lines (46 loc) · 924 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Learn about references
"""
def modify(k):
"""
Modify the content of a list
:param k: input list
:return: nothing
"""
# list are pass by reference
k.append(39)
print("k = ", k)
def replace(g):
"""
Replace input list, but create local copy
:param g: input list
:return: nothing
"""
g = [17, 48, 89]
print("g = ", g)
def replace_content(g):
"""
Replace the content of the input list
:param g: input list
:return: nothing
"""
g[0] = 88
g[1] = 22
g[2] = 44
print("g = ", g)
def main():
"""
test function
:return: nothing
"""
m = [9, 15, 24]
print("Before modify() m = ", m)
modify(m)
print("After modify() m = ", m)
replace(m)
print("After replace() m = ", m)
replace_content(m)
print("After replace_content() m = ", m)
if __name__ == '__main__':
main()
exit(0)