时间模块
import time
1-时间戳:
res=time.time()
2-结构化时间:
res=time.localtime()
3-结构化字符时间:
res=time.strftime('%Y-%m-%d %H:%M:%S')
res=time.asctime()
4-三种时间的转化
5-最重要的 将字符时间————时间戳
time_struc=time.strptime('2023-09-26 14:55:04','%Y-%m-%d %H:%M:%S')
time_stamp=time.mktime(time_struc)
random模块
import random
print(random.random()) #0~1的小数
print(random.randint(1,3)) #左右都能取
print(random.randrange(1,3))#左开右闭
print(random.choice([1,'aaa',[5,90,155]])) #
print(random.sample([1,'aaa',[5,90,155]],2)) #列表两个元素组合
print(random.uniform(1,3)) #1~3的浮点数
#取字母
# chr(90)=Z
# chr(65)=A
# chr(random.randint(65,90))
#验证码
res=' '
for i in range(6):
s1=chr(random.randint(65,90))
s2=str(random.randint(0,9))
res+=random.choice([s1,s2])
print(res)