1.时间
1 import time
2
3 #时间戳 #计算
4 # print(time.time()) #1481321748.481654秒
5
6 #结构化时间---当地时间
7 # print(time.localtime(1531242343))
8 # t=time.localtime()
9 # print(t.tm_year)
10 # print(t.tm_wday)
11 # #-----#结构化时间---UTC
12 # print(time.gmtime())
13
14 #-----将结构化时间转换成时间戳
15
16 # print(time.mktime(time.localtime()))
17 #------将结构化时间转成字符串时间strftime
18 # print(time.strftime("%Y---%m-%d %X",time.localtime()))
19 #------将字符串时间转成结构化时间strptime
20 # print(time.strptime("2016:12:24:17:50:36","%Y:%m:%d:%X"))
21
22 # print(time.asctime())
23 # print(time.ctime())
24
25
26 import datetime
27 print(datetime.datetime.now())
2.随机模块
1 import random
2
3 # ret=random.random()
4 # ret=random.randint(1,100)
5 # ret=random.randrange(1,3)
6 # ret=random.choice([11,22,33,44,55])
7 # ret=random.sample([11,22,33,44,55],2)
8 # ret=random.unifORM(1,4)
9 #
10 # print(ret)
11 # ret=[1,2,3,4,5]
12 # random.shuffle(ret)
13 # print(ret)
14 #
15 def v_code():
16 ret=""
17 for i in range(5):
18 num=random.randint(0,9)
19 alf=chr(random.randint(65,122))
20 s=str(random.choice([num,alf]))
21 ret+=s
22 return ret
23 print(v_code())