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()
それがオブジェクトのメモリ位置を与えると仮定します。どちらも同じ場所に保存していますが、 で x の値を変更しfunc()
ても外部には影響しません。