from import 语句
语法:
from 模块名 import 模块属性名 [as 属性新名1], 模块属性名2 [as 属性新名2]
作用:
将某模块的一个或多个属性导入到当前模块的作用域
示例:
from math import pi
from math import sin
from math import factorial as fac
from import * 语句
语法:
from 模块名 import *
作用:
将某模块的所有属性导入到当前的模块
示例:
from math import *
s = sin(pi/2)
print(factorial(10))
dir 函数
dir([对象]) 返回一个字符串列表
作用:
1. 如果没有参数调用,则返回当前作用域内所有变量的列表
2. 如果给定一个对象作为参数,则返回这个对象的所在变量(属性)列表
1) 对于一个模块,返回这个模块的全部变量
2) 对于一个类对象,返回类对象的所有变量,并递归基类对象的所有变量
3) 对于其它对象,返回所有变量、类变量和基类变量
数学模块 math
文档参见:
python_base_docs_html/数学模块math.html
时间模块 time
此模块提供了时间相关的函数
文档参见:
python_base_docs_html/时间模块time.html