""
我理解為空字串[]
為空串列
請問下面碼中的 args[0][:0]
該理解為什麼呢
用type(args[0][:0])
會顯示為<class 'list'>
請問它與[]
有什麼不同及特性呢?
我將它替換為[]
後 print(adder1(["a","b"],["c","d"]))
還能執行成功
執行 print(adder1("god","damn","it"))
就報錯了
不了解其中差異.....
def adder1(*args):
if type(args[0])==type(0):
sum = 0
else:
sum = args[0][:0]
for arg in args:
sum = sum + arg
return sum
print(adder1("god","damn","it"))
print(adder1(["a","b"],["c","d"]))
相关分类