""" 关键字任意实参,练习 """ # **kwargs对应函数会创建一个空字典用来存储多的键值对;*args是用来接收任意位置实参 def cars_info(maker, model, **kwargs): kwargs['maker_name'] = maker kwargs['model_name']
关键字任意实参,练习
"""
# **kwargs对应函数会创建一个空字典用来存储多的键值对;*args是用来接收任意位置实参
def cars_info(maker, model, **kwargs):
kwargs['maker_name'] = maker
kwargs['model_name'] = model
return kwargs
def pets_info(pet_name, *args):
print('pet_name:' + pet_name)
print('pet_info:')
for info in args:
print(info)
car_info = cars_info('Tom', 'BWM', color='blue', price=100000)
print(car_info)
pets_info('haha', 'nice', 'stoner')
print(pets_info)
# 打印顺序有点问题