场景1:可变对象类列表
def a(l):
l[0] = 1
print("\nValue of l = {0} in a()".format(l))
def b(l):
l = l + [9]
print("\nValue of l = {0} in b()".format(l))
l = [0]
a(l)
print("\nValue of l = {0} after executing a()".format(l))
b(l)
print("\nValue of l = {0} after executing b()".format(l))
输出
^{pr2}$问题
场景2:不可变对象,如整数
def a(l):
l = 1
print("\nValue of l = {0} in a()".format(l))
def b(l):
l = l + 9
print("\nValue of l = {0} in b()".format(l))
l = 0
a(l)
print("\nValue of l = {0} after executing a()".format(l))
b(l)
print("\nValue of l = {0} after executing b()".format(l))
输出
Value of l = 1 in a()
Value of l = 0 after executing a()
Value of l = 9 in b()
Value of l = 0 after executing b()
问题
我和很多人商量过了,但他们无法解释。有人能解释一下这个例子中使用的基本概念吗?在
目前没有回答
相关问题 更多 >
编程相关推荐