Python面试题汇总

1、深拷贝题目

def func(arg,li=[]):
	li.append(arg)
	return li
	
v1 = func(1)
print(v1)
v2 = func(2,[])  #开僻了一块内存空间(第1块内存空间,第2块内存空间)
print(v2)
v3 = func(3) #所以这里就是:[11,999,33,44,55]
print(v3)
n1 = [11,22,33,44,55]
n2 = n1 n3 = n1[:]
n1[0] = 666
n3[1] = 999
print(n1)
print(n2)
print(n3)

答案:

[666,22,33,44,55]
[666,22,33,44,55]
[11,999,33,44,55]

 

posted @ 2017-03-21 17:04  努力哥  阅读(833)  评论(0编辑  收藏  举报