模块
Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句。
模块让你能够有逻辑地组织你的 Python 代码段。
把相关的代码分配到一个模块里能让你的代码更好用,更易懂。
test.py:
def hello(input):
print("hello,%s"% input)
模块的引入
- import test
import test
test.hello('world')
输出:
hello,world
- from test import hello
from test import hello
hello('world')
输出:
hello,world
- import test as t
import test as t
t.hello('world')
输出:
hello,world