又是Python初學者問題,關於空串列等等

""我理解為空字串
[]為空串列
請問下面碼中的 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"]))
不负相思意
浏览 458回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python