1.作用域函数之一道有坑的面试题
# 2,(此题有坑)下面代码打印的结果分别是_________,________,________. def extendList(val, list=[]): # 默认值在内存只会产生一份 print(id(list)) list.append(val) return list list1 = extendList(10) list2 = extendList(123, []) list3 = extendList('a') print('list1=%s' % list1) # list1 = [10] print('list2=%s' % list2) # list2 = [123] print('list3=%s' % list3) # list = ['a'] """ 3236240122440 3236240122504 3236240122440 list1=[10, 'a'] list2=[123] list3=[10, 'a'] """