time模块 random模块
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                time模块 random模块
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                time模塊
time、sys等模塊是C語言實(shí)現(xiàn)的,內(nèi)置到了python解釋器的。而不是py文件。
導(dǎo)入模塊的時(shí)候,優(yōu)先到python解釋器,然后才會(huì)找py文件。
#時(shí)間戳 #計(jì)算 # print(time.time()) #1481321748.481654秒#結(jié)構(gòu)化時(shí)間---當(dāng)?shù)貢r(shí)間 # print(time.localtime(1531242343)) # t=time.localtime() # print(t.tm_year) # print(t.tm_wday) # #-----#結(jié)構(gòu)化時(shí)間---UTC # print(time.gmtime())#-----將結(jié)構(gòu)化時(shí)間轉(zhuǎn)換成時(shí)間戳# print(time.mktime(time.localtime())) #------將結(jié)構(gòu)化時(shí)間轉(zhuǎn)成字符串時(shí)間strftime #print(time.strftime("%Y---%m-%d %X",time.localtime())) #------將字符串時(shí)間轉(zhuǎn)成結(jié)構(gòu)化時(shí)間strptime #print(time.strptime("2016:12:24:17:50:36","%Y:%m:%d:%X"))# print(time.asctime()) # print(time.ctime())# import datetime # print(datetime.datetime.now()) #顯示的時(shí)間更符合我們要求?random模塊
?
import randomret=random.random() #0-1隨機(jī)浮點(diǎn)數(shù) ret=random.randint(1,3) ret=random.randrange(1,3) ret=random.choice([11,22,33,44,55]) ret=random.sample([11,22,33,44,55],2)#隨機(jī)選兩個(gè) ret=random.uniform(1,4)#1-4的隨機(jī)浮點(diǎn)數(shù)print(ret) ret=[1,2,3,4,5] random.shuffle(ret)#打亂順序 print(ret)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+=sreturn ret print(v_code())?
?
?
原文地址:https://www.cnblogs.com/yuanchenqi/articles/5732581.html
轉(zhuǎn)載于:https://www.cnblogs.com/jiawen010/p/9811701.html
總結(jié)
以上是生活随笔為你收集整理的time模块 random模块的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 如何使用MiniProfiler(附最新
- 下一篇: DNA甲基化检测服务
