Python – 使用 tqdm 模块创建进度条
在本文中,我们将了解如何借助 tqdm 模块制作进度条。进度条是一种图形控制元素,用于可视化扩展计算机操作的进度,例如下载、文件传输或安装。有时,图形伴随着百分比格式的进度文本表示。
所需模块:
Tqdm : Tqdm package is one of the more comprehensive packages for progress bars with python and is handy for those instances you want to build scripts that keep the users informed on the status of your application.
Time : This module provides various time-related functions, it is part of python’s standard library.
示例 1:
pip install tqdm
输出 :
示例 2:
# importing modules
from tqdm import trange
from time import sleep
# creating loop
for i in trange(10, desc ="loop "):
# slowing the for loop
sleep(0.1)
输出 :
示例 3:
# importing modules
from tqdm import tnrange
from time import sleep
# creating loop
for i in tnrange(2, desc ="loop 1"):
# creating nested loop
for j in tnrange(5, desc ="loop 2"):
# slowing the for loop
sleep(0.2)
输出 :
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。