python内置模块重要程度排名_论Python常见的内置模块
Python常見的內置模塊
系統的內置模塊
sys
hashlib
hmac
base64
time
datetime
sys模塊
sys.argv()# 在Python腳本傳參使用
sys.exit()# 系統退出
sys.getdefaultencoding()# 獲取系統默認編碼
getfilesystemencoding()# 獲取文件編碼
getrecursionlimit()# 獲取系統默認遞歸的最大層數
setrecursionlimit(num)# 設置遞歸的最大層數
getrefcount()# 獲取對象的引用計數的數量
import sys
print(sys.argv)
print(sys.version)
print(sys.maxint)
print(sys.path)
print(sys.platform)
print(sys.exit(0))
hashlib:
加密,散列加密(hash加密)
加密是否可逆:
|-- 可逆加密
根據加密和解密的秘鑰是否是同一個
|-- 對稱加密
DES
|-- 非對稱加密
RSA
|-- 不可逆加密
hash是典型的不可逆加密
MD5、shal256
import hashlib
md5 = hashlib.md5("需要加密的數據".encode("utf-8"))
base64模塊
|-- b64encode()
|-- b64decode()
time模塊:
asctime()# 獲取系統當前時間
ctime()# 獲取系統當前時間
time()# 獲取當前的時間戳
localtime()# 返回當前時間,以類似于元組的對象
t = time.localtime()
print(“當前時間是%s-%s-%s %s:%s:%s” %(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec))
time.strftime()# 將時間對象格式化成字符串
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
time.strptime()# 時間字符串轉換為時間對象
time.strptime(‘2019/09/18 21:02:44’, “%Y/%m/%d %H:%M:%S”)
時間戳(timestamp) :通常來說,時間戳表示的是從1970年1月1日00:00:00開始按秒計算的偏移量。我們運行“type(time.time())”,返回的是float類型。
格式化的時間字符串
元組(struct_time) :struct_time元組共有9個元素共九個元素:(年,月,日,時,分,秒,一年中第幾周,一年中第幾天,夏令時)
import time
time.sleep(5)
print(“睡眠5s”)
#sleep() #線程推遲自定的時間運行,單位為秒
#clock()
#這個需要注意啦,在不同的系統上含義不同,在unix系統上,它返回的是’進程時間’,用秒表示的浮點數(時間戳)
#在windows中,第一次調用,返回的是進程運行的實際時間,而第二次之后的調用是自第一次調用后到現在的運行
#的時間,即兩次的時間差 返回當前時間的時間戳(以秒計算,從1970年1月1日00:00:00開始到現在的時間差)
print(time.time()) # 結果:1537428578.9319177
將一個時間戳轉換為當前時區
t = time.localtime()
print(t)
time.struct_time(tm_year=2018, tm_mon=9, tm_mday=20, tm_hour=15, tm_min=33, tm_sec=9, tm_wday=3, tm_yday=263, tm_isdst=0)
year = t.tm_year
month = t.tm_mon
print(year) #2018
gmtime()方法是將一個時間戳轉換為UTC時區(0時區)的struct_time。
print(time.gmtime())
time.struct_time(tm_year=2018, tm_mon=9, tm_mday=20, tm_hour=7, tm_min=37, tm_sec=46, tm_wday=3, tm_yday=263, tm_isdst=0)
print(time.gmtime(time.time()-9000))
time.struct_time(tm_year=2018, tm_mon=9, tm_mday=20, tm_hour=5, tm_min=17, tm_sec=10, tm_wday=3, tm_yday=263, tm_isdst=0)
print(time.mktime(time.localtime())) # 結果1537429976.0
print(time.strftime("%Y-%m-%d %X",time.localtime())) #結果 2018-09-20 15:58:28
print(time.strptime(“2016:12:26:12:34:33”,"%Y:%m:%d:%X"))
#結果time.struct_time(tm_year=2016, tm_mon=12, tm_mday=26, tm_hour=12, tm_min=34, tm_sec=33, tm_wday=0, tm_yday=361, tm_isdst=-1)
print(time.asctime()) #Thu Sep 20 16:04:16 2018 把結構換時間轉換成固定的字符串表達式
print(time.ctime()) # Thu Sep 20 16:04:16 2018 把時間戳時間轉換成固定的字符串表達式
datetime
|-- datetime.datetime.now()# 獲取系統當前時間
標簽:內置,加密,Python,sys,tm,時間,模塊,time,print
來源: https://blog.csdn.net/qq_43199083/article/details/101030248
總結
以上是生活随笔為你收集整理的python内置模块重要程度排名_论Python常见的内置模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做试管婴儿期间吃什么好
- 下一篇: java jms消息删除_activem