日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

time模块 random模块

發布時間:2024/4/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 time模块 random模块 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

time模塊

time、sys等模塊是C語言實現的,內置到了python解釋器的。而不是py文件。

導入模塊的時候,優先到python解釋器,然后才會找py文件。

#時間戳 #計算 # print(time.time()) #1481321748.481654秒#結構化時間---當地時間 # print(time.localtime(1531242343)) # t=time.localtime() # print(t.tm_year) # print(t.tm_wday) # #-----#結構化時間---UTC # print(time.gmtime())#-----將結構化時間轉換成時間戳# print(time.mktime(time.localtime())) #------將結構化時間轉成字符串時間strftime #print(time.strftime("%Y---%m-%d %X",time.localtime())) #------將字符串時間轉成結構化時間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()) #顯示的時間更符合我們要求

?random模塊

?

import randomret=random.random() #0-1隨機浮點數 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)#隨機選兩個 ret=random.uniform(1,4)#1-4的隨機浮點數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

轉載于:https://www.cnblogs.com/jiawen010/p/9811701.html

總結

以上是生活随笔為你收集整理的time模块 random模块的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。