【发布时间】:2015-03-01 11:08:30
【问题描述】:
def func(x):
print "inside function" ,id(x)
x = 2
x = 50
print "outside function" ,id(x)
print 'Value of x before function call is', x
func(x)
print 'Value of x after function call is', x
输出:
outside function 6486996
Value of x before function call is 50
inside function 6486996
Value of x after function call is 50
假设id() 给出了对象的内存位置。即使两者都保存在同一个位置,如果在func()中更改了x值,则不会影响到外部。
【问题讨论】:
标签: python call-by-value