zl程序教程

您现在的位置是:首页 >  Python

当前栏目

python 打印进度条

2023-04-18 14:13:57 时间
import time
recv_size=0
total_size=1024

while recv_size < total_size:
    time.sleep(0.1)
    recv_size+=1024
    #打印进度条
    percent=recv_size / total_size
    res = int(50 * percent) * '#'
    print('
[%-50s] %d%%' % (res,int(100 * percent)),end='') # end='' 打印以‘’结尾,打印% 需要使用两个%%

效果:

[##################################################] 100%
Process finished with exit code 0