def extendList(val, list=[]): # []默认参数的只指向一个地址 list.append(val) return list list1 = extendList(10) list2 = extendList(123, []) list3 = extendList('a') print('list1=%s' % list1) print('list2=%s' % list2) print('list3=%s' % list3) #下面代码打印的结果分别是[10, a], [123], [10, a]
def extendList(val, list=[]): # []默认参数的只指向一个地址 list.append(val) return list list1 = extendList(10) print('list1=%s' % list1) list2 = extendList(123, []) print('list2=%s' % list2) list3 = extendList('a') print('list3=%s' % list3) #下面代码打印的结果分别是[10,], [123], [10, a]