# -*- coding:utf-8 -*-
'''
print 中的 end = '\r' 是一个转义符,作用是让光标重新回到首行
默认是'\n'换行符,windows系统下如果设置后不改回默认值会一直有效,不懂为什么
'''
import sys,time
# 变量
total = 153
for i in range(total):
if i+1 == total:
percent = 100.0
print('当前核算进度 : %s [%d/%d]'%(str(percent)+'%',i+1,total),end='\n')
else:
percent = round(1.0 * i / total * 100,2)
print('当前核算进度 : %s [%d/%d]'%(str(percent)+'%',i+1,total),end='\r')
time.sleep(0.01)
实现效果: