Discuss / Python / 里面存放参数的不是集合吗?为什么我传多个参数会报错,一个参数没反应。。。

里面存放参数的不是集合吗?为什么我传多个参数会报错,一个参数没反应。。。

Topic source

Dicetequiero

#1 Created at ... [Delete] [Delete and Lock User]
在此插入代码

def a(L=None): if L is None: L=[] L.append('ENd')

    return L

a() ['ENd'] a(1)

a(1,2,3) Traceback (most recent call last): File "<pyshell#118>", line 1, in <module> a(1,2,3) TypeError: a() takes from 0 to 1 positional arguments but 3 were given

小匡吉匡

#2 Created at ... [Delete] [Delete and Lock User]

注意你return的位置有误

传递多个参数要写成list的形式,例如:a([1,2,3])

L.append('ENd') 此方法只属于list 吗?


  • 1

Reply