""我理解為空字串[]為空串列請問下面碼中的 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"]))
添加回答
举报
0/150
提交
取消