模块:可以被公共调用的。
time
import time
print(time.time()) 时间戳方式显示时间。
time.sleep(3) 休眠3秒
time.clock() 计算cpu执行时间
time.gmtime() 结构化时间
time.locatime() 本地化时间
struct_time = time.localtime()
print(time.strftime('%Y--%m--%d %H:%M:%S',struct_time)) 字符串时间
print(time.strptime('2018--12--10 15:11:05','%Y--%m--%d %H:%M:%S')) 转换成结构化时间
a = time.striptime('2018--12--10 15:11:05','%Y--%m--%d %H:%M:%S')
a.tm_year,a.tm_mday,a.tm_wday
print(time.ctime()) ctime加参数的话,会计算出时间戳再显示当前时间
print(time.mktime(time.localtime())) 计算时间戳秒数
######
datetime模块
import datatime
print(datetime.datetime.now())
########
random模块 #随机数模块
import random
print(random.random()) 0-1之间随机生成一个随机数
print(random.randint(1,8)) 1-8之间随机成成一个整数,包括8
print(random.choice('asdasdasd') 字符串随机生成一个
print(random.sample(['asd','1',asd,2]) 从序列里随机选取2个
print(random.randrange(1,3)) 随机取1个数,不包含3