在 python 用 import 或者 from...import 来导入相应的模块。
将整个模块(somemodule)导入,格式为: import somemodule
从某个模块中导入某个函数,格式为: from somemodule import somefunction
从某个模块中导入多个函数,格式为: from somemodule import firstfunc, secondfunc, thirdfunc
将某个模块中的全部函数导入,格式为: from somemodule import *
# 引入圆周率pi
from math import pi
# 圆的半径
r = 5;
# 计算圆的面积
s= pi*r*r
# 输出圆的面积,保留两位小数
print('%.2f' % s)
查看模块的所有函数
使用dir
import math
print(dir(math))
# 过滤以下画线开头的成员
print([e for e in dir(math) if not e.startswith('_')])