模块是python的核心,每一个以.py结尾的文件都是模块,模块能定义函数,类和变量,模块里也能包含可执行的代码。
Python 的 from 语句让你从模块中导入一个指定的部分到当前命名空间中。
模块文件:(model_function_demo.py):
#每一个以.py结尾的文件都是模块,模块能定义函数,类和变量,模块里也能包含可执行的代码。
def show(name,age):
print(name)
print(age)
print("我的名字是:%s, 我的年龄是:%6d" % (name, age))
#
# print("我的名字是:%s, 我的年龄是:%6d"%{name,age})
name="beijing";
def jiujiu():
m=1;
while m<=9:
n=1;
while n<=m:
print("%d*%d=%d"%(n,m,(m*n)),end="\t");
n=n+1;
print("");
m=m+1;
调用文件(test_module.py):
#测试模型文件
'''
import model_function_demo as mfd
mfd.show("liu",18);
mfd.jiujiu();
'''
#Python 的 from 语句让你从模块中导入一个指定的部分到当前命名空间中。语法如下:
from model_function_demo import show
show("liu",34)
from model_function_demo import name
print(name)