1 个回答|222 次阅读
如果不知道将传递到函数中的参数个数,可在函数定义中的参数名称之前添加 一个星号 *
这样,该函数将接收参数元组,并可以相应地访问这些元组项:
def my_function(*args):
print("The fruit name is " + args[2])
#调用函数
my_function("apple", "orange", "banana")
执行结果:
The fruit name is banana
请先 登录 后评论