可以运行这样的函数:
def call(a,*alphabets,*numbers):
print(a)
print(alphabets)
print(numbers)
我会收到以下错误:
File "<ipython-input-331-ddaef8a7e66f>", line 1
def call(a,*alphabets,*numbers):
^
SyntaxError: invalid syntax
有人可以告诉我是否有另一种方法可以这样做?
非常简单:要求呼叫者通过两个列表(或元组或其他(:
def call(a,alphabets=None,numbers=None):
if alphabets is None:
alphabets = []
if numbers is None:
numbers = []
print(a)
print(alphabets)
print(numbers)
call("?")
call("?", ["a", "b", "c"])
call("?", ["a", "b", "c"], (1, 2, 3))
call("?"), None, (1, 2, 3))
# etc