Pythonb標準庫
1.time庫

import time
print(time.localtime())
print(time.gmtime())
結果:

time.ctime()
結果:


t1_start=time.time()
t2_start=time.perf_counter()
t3_start=time.process_time()
print(t1_start)
print(t2_start)
print(t3_start)
res=0
for i in range(100000):
res+=i
time.sleep(5)
t1_end=time.time()
t2_end=time.perf_counter()
t3_end=time.process_time()
print("time:{:.3f}秒".format(t1_end-t1_start))
print("ime.perf_counter:{:.3f}秒".format(t2_end-t2_start))
print("time.process_time:{:.3f}秒".format(t3_end-t3_start))
結果:

random庫

from random import *
seed(10)
print(random())
seed(10)
print(random())
print(random())
結果:



collections庫——容器資料型別
1.namedtuple——具名元組


import collections
p=(1,2)
Point = collections.namedtuple("Point",["x","y"])
p=Point(1,y=2)
p
結果:
2.couter——計數器工具
from collections import Counter
s="sdfhbcsdvvporsjpas"
str_s=Counter(s)
print(str_s)
結果:
3,deque——雙向佇列

itertools庫——迭代器
1.排列組合迭代器
(1)product——笛卡爾積
(2)permutation——排列
(3)combinations——組合
(4)combinations_with_replacement——元素可重復組合
2.拉鏈
(1)zip
(2)zip_longest——長拉鏈
3.無窮迭代器
(1)count(start=o,step=1)——計數
(2)cycle(iterable)——回圈
(3)repeat(object[,times])——重復
4.其它
(1)chain(iterables)——鎖鏈
(2)enumerable(iterable,start=0)——列舉(Python內置)
(3)groupby(iterable,key=None)——分組
總結




轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/230302.html
標籤:python
上一篇:13. 如果自己寫的 Python 程式出錯了,怎么辦?
下一篇:PAT (Basic Level) Practice 1035 插入與歸并 (25分) Python非遞回實作(測驗點2有坑)
