第8章 函数
def printMaterial(name, *materials):
print("costumer " + name + ":")
for material in materials:
print(material)
print()
printMaterial("John", "beef", "tuna")
printMaterial("Alice", "peanut")
printMaterial("Tom", "tomato", "egg", "cheese")
def build_profile(first, last, **user_info):
profile = {}
profile['first_name'] = first
profile['last_name'] = last
for key, value in user_info.items():
profile[key] = value
return profile
user_profile = build_profile(
'albert', 'ye', location='guangzhou', field='computer science')
print(user_profile)
def make_car(name, location, **car_info):
profile = {}
profile['name'] = name
profile['location'] = location
for key, value in car_info.items():
profile[key] = value
return profile
car = make_car('subaru', 'outback', color='blue', tow_package=True)
print(car)