Function Parameters as References
Posted April 27, 2021 by clannadzsy ‐ 1 min read
"""
from Fluent Python 2nd Example 6-11
"""
def f(p1, p2):
p1 += p2
return p1
x, y = 1, 2
f(x, y)
# x = 1, y = 2
a = [1, 2]
b = [3, 4]
f(a, b)
# a 的值改变了
# a = [1, 2, 3, 4]
# b = [3, 4]
m = (1, 2)
n = (3, 4)
f(m, n)
# m = (1, 2)
# n = (3, 4)