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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 中有趣的库tqdm

發布時間:2025/3/20 python 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 中有趣的库tqdm 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Tqdm 是 Python 進度條庫,可以在 Python 長循環中添加一個進度提示信息用法:tqdm(iterator)

方法1:

import time from tqdm import tqdm for i in tqdm(range(100)): time.sleep(0.01)

方法2:

''' 遇到問題沒人解答?小編創建了一個Python學習交流QQ群:857662006 尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學習教程和PDF電子書! ''' import time from tqdm import trangefor i in trange(100):time.sleep(0.01)

結果:

0%| | 0/100 [00:00<?, ?it/s]11%|| 11/100 [00:00<00:00, 100.00it/s]22%|██▏ | 22/100 [00:00<00:00, 100.00it/s]32%|███▏ | 32/100 [00:00<00:00, 100.00it/s]43%|████▎ | 43/100 [00:00<00:00, 100.00it/s]54%|█████▍ | 54/100 [00:00<00:00, 100.00it/s]64%|██████▍ | 64/100 [00:00<00:00, 99.11it/s] 74%|███████▍ | 74/100 [00:00<00:00, 99.37it/s]85%|████████▌ | 85/100 [00:00<00:00, 99.56it/s]95%|█████████▌| 95/100 [00:00<00:00, 99.69it/s] 100%|██████████| 100/100 [00:01<00:00, 99.70it/s]

可以為進度條設置描述:

import time from tqdm import tqdmpbar = tqdm(["a", "b", "c", "d"]) for char in pbar: # 設置描述pbar.set_description("Processing %s" % char)time.sleep(1)

結果:

0%| | 0/4 [00:00<?, ?it/s] Processing a: 25%|██▌ | 1/4 [00:01<00:03, 1.00it/s] Processing b: 50%|█████ | 2/4 [00:02<00:02, 1.00it/s] Processing c: 75%|███████▌ | 3/4 [00:03<00:01, 1.00it/s] Processing d: 100%|██████████| 4/4 [00:04<00:00, 1.00it/s] ''' 遇到問題沒人解答?小編創建了一個Python學習交流QQ群:857662006 尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學習教程和PDF電子書! ''' import time from tqdm import tqdm# 一共200個,每次更新10,一共更新20次 with tqdm(total=200) as pbar:for i in range(20):pbar.update(10) time.sleep(0.1)#方法2: pbar = tqdm(total=200) for i in range(20): pbar.update(10)time.sleep(0.1) # close() 不要也沒出問題? pbar.close()

結果:

0%| | 0/200 [00:00<?, ?it/s]15%|█▌ | 30/200 [00:00<00:01, 150.00it/s]25%|██▌ | 50/200 [00:00<00:01, 130.43it/s]30%|███ | 60/200 [00:00<00:01, 119.52it/s]40%|████ | 80/200 [00:00<00:01, 112.91it/s]50%|█████ | 100/200 [00:00<00:00, 108.70it/s]55%|█████▌ | 110/200 [00:01<00:00, 105.93it/s]65%|██████▌ | 130/200 [00:01<00:00, 104.08it/s]75%|███████▌ | 150/200 [00:01<00:00, 102.82it/s]80%|████████ | 160/200 [00:01<00:00, 101.96it/s]85%|████████▌ | 170/200 [00:01<00:00, 96.38it/s] 90%|█████████ | 180/200 [00:01<00:00, 97.44it/s] 100%|██████████| 200/200 [00:01<00:00, 98.19it/s]

總結

以上是生活随笔為你收集整理的python 中有趣的库tqdm的全部內容,希望文章能夠幫你解決所遇到的問題。

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