随机数 import random
1.随机一个整数randint() 包含开头结尾:print(random.randint(1,43)
2.随即一个小数random() 0~1:print(random.random()
3. 随机一个范围randrange(开始值,结束值,步长值) 含头不含尾0-9:print(random.randrange(0,10,2)
4. choice() 随机一个元素:print(random.choice(’“a1”,“b2”,“c3”,“d4”’)
时间模块import time**
1.时间戳:1970-01-01 00:00:00 (格林威治时间0时区) 秒数 :print(time.time()
优点:存储方便,占有空间小,方便计算操作
缺点:不方便查看时间
2.时间元组:print(time.localtime()
优点:方便程序调用
缺点:没有格式
3.时间字符串(需要时间的格式):print(time.strftime("%d/%m/%Y %H:%M:%S")
gmtime :utc 国际标准时间,localtime :本地时间
(1)时间戳转化为时间元组
print(time.gmtime(72047023)
print(time.localtime(72047023)
(2)时间元组转为时间字符串
print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime(0))
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(0))
(3) 时间字符串转为时间元组
print(time.strptime(“2200-11-11 12:30:29”,"%Y-%m-%d %H:%M:%S")
(4)时间元组转为时间戳
print(time.mktime(time.strptime(“2200-11-11 12:30:29”,"%Y-%m-%d %H:%M:%S"))