# 案例导入pizza.py模块defmake_pizza(size,*toppings):'''概述要制作的比萨'''print("\nMaking a "+str(size)+"-inch pizza with the following toppings:")for toppping in toppings:print("- "+ topping)import pizza
pizza.make_pizza(16,'pepperoni')
pizza.make_pizza(12,'mushrooms','green peppers','extra cheese')
导入特定的函数
导入模块中的特定函数
通过用逗号分隔函数名,可根据需要从模块中导入任意数量的函数。
# 案例from module_name import function_name
from module_name import function_0, function_1,function_2
from pizza import make_pizza
make_pizza(16,'pepperoni')
make_pizza(12,'mushrooms','green peppers','extra cheese')# 使用这种语法,调用函数时无需使用句点