选择一个你编写的且只包含一个函数的程序,并将这个函数放在另一个文件中。在主程序文件中,使用下述各种方法导入这个函数,再调用它:
import module_name
from module_name import function_name
from module_name import function_name as fn
import module_name as mn
from module_name import *
还是以做pizza的函数为例

(1)import module_name
导入整个模块

(2)from module_name import function_name
导入特定的函数

(3)from module_name import function_name as fn
使用as给函数指定别名

(4)import module_name as mn
使用as给模块指定别名

(5)from module_name import *
使用星号(*)运算符可让Python导入模块中的所有函数

网友评论