• 用python的time库写一个进度条


    运算符

    算数运算

    如a=10,b=20

    +两个数相加 a+b=30

    -两个数相减 a-b=-10

    *两个数相乘 a*****b =200

    /两个数相除b/a=2

    %取模,并返回余数b%a=0

    幂,a**b=10的20次方

    .strip()去除多余空格字符串

    .isdigit()判断是否为数字字符串

    time库

    • 获取时间

      time.timr()

      time.ctime()

      time.gmtime()

    • 格式化

    ​ time.strftime

    ​ time.strptime

    • 程序计时

      time.sleep()

      time.perf_counter()

    利用time库写一个进度条

    • 源代码

      import time
      
      count = 10
      print("....请开始执行....")
      for i in range(count + 1):
          a = "#" * i
          b = "." * (count - i)
          c = (i/count) * 100
          print(f"[{a}->{b}]{c}%")
          time.sleep(0.2)
      print("......执行结束.....")
      

    优化后的进度条

    • 源代码

      import time
      
      print("开始执行".center(50, '-'))#把开始执行放中间,用50个-包围
      start = time.perf_counter()
      count = 100
      for i in range(count + 1):
          a = "#" * i
          b = "." * (count - i)
          c = (i/count) * 100
          res = time.perf_counter() - start
          #print(f"
      [{a}->{b}]{c:.2f}%{res:.2f}s",end="")
          print(f"33[1;31m
      [{a}->{b}]{c:.2f}%{res:.2f}s33[0m", end="")
          # 上面加了就可以改变颜色
          #print(f"33[1;31;40m
      [{a}->{b}]{c:.2f}%{res:.2f}s33[0m", end="")
          #上面这行还可以改变进度条背景颜色
          time.sleep(0.05)
      print("
      " + "结束执行".center(50, '-'))
      
      ```![](https://img2018.cnblogs.com/blog/1843751/201910/1843751-20191023191027296-773847820.png)
  • 相关阅读:
    okhttp之源码学习1
    Retrofit2之源码解析2
    Retrofit2之源码解析1
    retrofit之笔记内容
    retrofit之基本笔记
    retrofit之基本内容
    rxjava-源码分析
    rxjava-基本内容解析
    rxjava_几类转换
    java几种常见的编码
  • 原文地址:https://www.cnblogs.com/yafeng666/p/11728176.html
Copyright © 2020-2023  润新知