BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #74632同步于 2013/10/18
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

【Python】初学者求问copy函数

hanhandou
2013/10/18镜像同步7 回复
contact = {} contact_list = [] while 1: contact['name'] = raw_input("please input name: ") contact['phone'] = raw_input("please input phone number: ") contact_list.append(contact.copy()) go_on = raw_input("continue?\n") if go_on == "yes": pass elif go_on == "no": break else: print "you didn't say no\n" i = 1 for contact in contact_list: print "%d: name=%s" % (i, contact['name']) print "%d: phone=%s" % (i, contact['phone']) i = i + 1 -------------------------------------------------------------- 其中copy()的作用是what,有copy()和没有copy()结果不同? [ema13]
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
hanhandou机器人#1 · 2013/10/18
不知道应该发到哪个版块,就这个吧~ hoho
Milrivel机器人#2 · 2013/10/18
a = {1 : 1, 2 : 2} b = [] b.append(a) b[0][1] = 3 print a[1] a = {1 : 1, 2 : 2} b = [] b.append(a.copy()) b[0][1] = 3 print a[1] #Run it and you can see the difference
hanhandou机器人#3 · 2013/10/18
【 在 Milrivel 的大作中提到: 】 : a = {1 : 1, 2 : 2} : b = [] : b.append(a) : ................... Thanks,I know there has been some difference. I wanna why?
hanhandou机器人#4 · 2013/10/18
【 在 Milrivel 的大作中提到: 】 : a = {1 : 1, 2 : 2} : b = [] : b.append(a) : ................... soga,貌似懂了,多谢
Milrivel机器人#5 · 2013/10/18
If you don't use copy, the thing that b will append is just a pointer 【 在 hanhandou 的大作中提到: 】 : : soga,貌似懂了,多谢
hanhandou机器人#6 · 2013/10/19
soga,thanks a lot iPhone客户端1.3发布
justinleoye机器人#7 · 2013/10/19
【 在 Milrivel 的大作中提到: 】 : If you don't use copy, the thing that b will append is just a pointer 好不容易遇到个可以回答的问题,结果被你抢先了!