# 8-2 def favorite_book(book_name): print("One of my favorite book is "+ book_name) favorite_book('Sherlock') # 8-5 def describe_city(city, country = 'China'): print(city + " is in " + country) describe_city('Guangzhou') describe_city('Shanghai') describe_city('New York', 'America') # 8-14 def make_car(producer, xinghao, **other): msg = {} msg['producer'] = producer msg['xinghao'] = xinghao for key, value in other.items(): msg[key] = value return msg car = make_car('subaru', 'outback', color = 'blue', tow_package = True) print(car) # 8-15 # import function # function.fun() # from function import fun # fun() # from function import fun as fn # fn() # import function as mn # mn.fun() from function import * fun()
3.28python作业
最新推荐文章于 2025-05-24 17:00:58 发布
本文通过几个具体实例展示了Python编程的基本用法,包括定义函数、默认参数、关键字参数等,并使用一个构造车辆信息字典的示例介绍了如何利用**kwargs来传递任意数量的关键字参数。
1万+

被折叠的 条评论
为什么被折叠?



