求教python问题,在线等 (转载)# Programming - 葵花宝典
M*T
1 楼
【 以下文字转载自 biojailbreak 俱乐部 】
发信人: MAAT (gogogo), 信区: biojailbreak
标 题: 求教python问题,在线等
发信站: BBS 未名空间站 (Thu Oct 23 23:38:16 2014, 美东)
如何解释一下的输入结果,在modify的方法结束以后,发生了什么,为啥b的指针又给
回到了原来的位置??很明显方法是传递了指针进去,但是为啥方法运行完了就变会原
来了?
class num:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def modify(a, b):
print('the memory address of argu 1nd para before =')
print(a)
print('the memory address of argu 2nd para before =')
print(b)
b = a
b.x = 10000
print('the memory address of argu 1nd para after =')
print(a)
print('the memory address of argu 2nd para after =')
print(b)
if __name__ == "__main__":
e = num(4,5,6)
f = num(7,8,9)
print('object e before modify')
print(e)
print('object f before modify')
print(f)
modify(e, f)
print('object f after modify')
print(f)
print(f.x, f.y, f.z)
发信人: MAAT (gogogo), 信区: biojailbreak
标 题: 求教python问题,在线等
发信站: BBS 未名空间站 (Thu Oct 23 23:38:16 2014, 美东)
如何解释一下的输入结果,在modify的方法结束以后,发生了什么,为啥b的指针又给
回到了原来的位置??很明显方法是传递了指针进去,但是为啥方法运行完了就变会原
来了?
class num:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def modify(a, b):
print('the memory address of argu 1nd para before =')
print(a)
print('the memory address of argu 2nd para before =')
print(b)
b = a
b.x = 10000
print('the memory address of argu 1nd para after =')
print(a)
print('the memory address of argu 2nd para after =')
print(b)
if __name__ == "__main__":
e = num(4,5,6)
f = num(7,8,9)
print('object e before modify')
print(e)
print('object f before modify')
print(f)
modify(e, f)
print('object f after modify')
print(f)
print(f.x, f.y, f.z)