您好,欢迎来到欧得旅游网。
搜索
您的当前位置:首页函数参数*arg和参数**arg区别

函数参数*arg和参数**arg区别

来源:欧得旅游网
def sandwich(*toppings):
print("\nMaking a sandwich with the following toppings: ")
print(toppings)
for topping in toppings:
print(topping)
sandwich('banna','apple')
sandwich('apple','beef','pairs')
sandwich('apple')

参数*toppings意思是创建了一个名为toppings的元组,可以通过遍历循环将其打印出来。并且它可以接纳任意数量实参的形参,这种形参都放在函数参数的最后。


def car(make_bussines,type_car,**user_info):
car = {}
car['make_bussines'] = make_bussines
car['type_car'] = type_car
for key,value in user_info.items():
car[key] = value
return car
make_car = car('subaru','outback',color = 'blue',tow_package = 'True')

print(make_car)

而**user_info则是创建了一个字典,传参的时候必须是

make_car = car('subaru','outback',color = 'blue',tow_package = 'True')

键-值对应传递

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- ovod.cn 版权所有 湘ICP备2023023988号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务