程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Text progress bar for Python string cases

編輯:Python

About bloggers : Former Internet manufacturer tencent staff , Network security giant Venustech staff , Alibaba cloud development community expert blogger , WeChat official account java Quality creators of basic notes ,csdn High quality creative bloggers , Entrepreneur , Knowledge sharers , Welcome to your attention , give the thumbs-up , Collection .


One 、 background

Python Is an easy to learn 、 Powerful programming language . It provides an efficient high-level data structure , It's also a simple and effective way of object-oriented programming .Python Elegant grammar and dynamic typing and the essence of interpretive language , Make it an ideal language for scripting and rapid application development on most platforms . Now let's introduce python Realize the text progress bar through string related knowledge .


Two 、 actual combat

example : Programming , Analog output simple non refresh text progress bar . It is required to divide the whole task into 100 A unit of , Every execution 10% Output a progress bar , Each line of output contains a percentage of progress 、 Represents the completed part (**) And unfinished parts (..) Two characters of , And a small arrow that follows the degree of completion , The style is as follows :

%10 [**->………………]

The code is as follows , Each line is explained in the notes .

import time # Import time modular
scale = 10 # Variable scale Used to indicate the accuracy of the output progress bar
print("---------- Execution start ----------") # Output
for i in range(scale + 1): # Loop variable from 0 To 10
a = "**" * i # use “*” Indicates the completed part
b = ".." * (scale - i) # use “.” Indicates the unfinished part
c = (i / scale) * 100 # Calculate the completion percentage and assign it to c
print("%{:^3.0f}[{}->{}]".format(c, a, b)) # Format output
time.sleep(0.1) # Pause 0.1 second
print("---------- end of execution ----------") # Output

adopt pycharm The results are as follows .

Insert picture description here


3、 ... and 、 Reference resources

1、 Liao Xuefeng's official website 2、python Official website 3、Python Programming case tutorial


Four 、 summary

That's about Python Realize the text progress bar through string related knowledge ., You can refer to it , Relevant knowledge will be continuously updated later , Make progress together .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved