专业编程基础技术教程

网站首页 > 基础教程 正文

Python进度条制作之time

ccvgpt 2024-08-15 20:24:43 基础教程 10 ℃

笔记记录20221119:


# _*_ coding: utf-8 _*_
import time

"""
1,\r 一般用在print()中对要打印的结果做格式化处理, 表示将光标的位置回退到本行的开头位置。
2,其中end="",表示不换行
3,其中%s,格式化进行输出,位置进行预留,这里预留了50个字符
"""
list1 = [12,23,34,45,56,67,78,89]
j = 1
leng = len(list1)
for i in list1:
  time.sleep(0.5)
  percent = j / leng
  strvar = int(percent * 50) * "#"
  print("\r[%-50s] %d%%" % (strvar, percent * 100), end="")
  j += 1

Python进度条制作之time

最近发表
标签列表