python标准库
第三方模块
自定义模块
time
import time # #时间戳 #计算 print(time.time()) #1526978022.5141296 time.sleep(5) print(time.localtime(1511242343)) #time.struct_time(tm_year=2017, tm_mon=11, tm_mday=21, tm_hour=13, tm_min=32, tm_sec=23, tm_wday=1, tm_yday=325, tm_isdst=0) t=time.localtime() print(t.tm_year) #2018 print(t.tm_wday) #1 # #-----#结构化时间---UTC print(time.gmtime()) #time.struct_time(tm_year=2018, tm_mon=5, tm_mday=22, tm_hour=8, tm_min=41, tm_sec=33, tm_wday=1, tm_yday=142, tm_isdst=0) #-----将结构化时间转换成时间戳 print(time.mktime(time.localtime())) #1526978549.0 #------将结构化时间转成字符串时间strftime print(time.strftime("%Y---%m-%d %X",time.localtime())) #2018---05-22 16:42:54 #------将字符串时间转成结构化时间strptime print(time.strptime("2016:12:24:17:50:36","%Y:%m:%d:%X")) #time.struct_time(tm_year=2016, tm_mon=12, tm_mday=24, tm_hour=17, tm_min=50, tm_sec=36, tm_wday=5, tm_yday=359, tm_isdst=-1) print(time.asctime()) #Tue May 22 16:43:19 2018 print(time.ctime()) #Tue May 22 16:43:19 2018
random
import random ret=random.random() #0.8118528300987962 0到1的浮点数 ret=random.randint(1,3) #3 整型 ret=random.randrange(1,3) #2 ret=random.choice([11,22,33,44,55]) #55 随机 ret=random.sample([11,22,33,44,55],2) #[22, 11] ret=random.uniform(1,4) #1.2265044697702803 1到4的浮点数 ret=[1,2,3,4,5] random.shuffle(ret) print(ret) #[3, 4, 5, 1, 2] #随机排序 def v_code(): ret="" for i in range(5): num=random.randint(0,9) alf=chr(random.randint(65,122)) s=str(random.choice([num,alf])) ret+=s return ret print(v_code()) #8EN39