day21-python模块
生活随笔
收集整理的這篇文章主要介紹了
day21-python模块
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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())?
轉載于:https://www.cnblogs.com/sqy-yyr/p/10888205.html
總結
以上是生活随笔為你收集整理的day21-python模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 12.13记录//QQDemo示例程序源
- 下一篇: 用c#写的一个局域网聊天客户端 类似小飞