代码:
import time
scale = 10
print("------执行开始------")
for i in range(scale+1): # i = 0,1,2,...,9,10
a, b = "**" * i, ".." * (scale - i)
c = (i/scale)*100
print("%{:^4.0f}[{}->{}]".format(c,a,b))
time.sleep(0.1)
print("------执行结束------")
控制台输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS F:\TEST> & 'D:\Python\Python37\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '59575' '--' 'f:\TEST\1.py'
------执行开始------
% 0 [->....................]
% 10 [**->..................]
% 20 [****->................]
% 30 [******->..............]
% 40 [********->............]
% 50 [**********->..........]
% 60 [************->........]
% 70 [**************->......]
% 80 [****************->....]
% 90 [******************->..]
%100 [********************->]
------执行结束------
PS F:\TEST>
代码:
import time
for i in range(101):
print("\r{:3}%".format(i),end="")
time.sleep(0.05)
控制台输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS F:\TEST> & 'D:\Python\Python37\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '59594' '--' 'f:\TEST\1.py'
94%
代码:
import time
print("##"*20,end="")
time.sleep(2)
print("\r****")
控制台输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS F:\TEST> & 'D:\Python\Python37\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '59611' '--' 'f:\TEST\1.py'
****####################################
PS F:\TEST>
代码:
import time
scale = 50
print("执行开始".center(scale//2,'-'))
t = time.clock()
for i in range(scale+1):
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
t = time.clock()
# print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="\n")
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="")
time.sleep(0.05)
print("\n林祖泉:"+"执行结束".center(scale//2,'-'))
控制台输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS F:\TEST> & 'D:\Python\Python37\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '59628' '--' 'f:\TEST\1.py'
-----------执行开始----------
f:\TEST\1.py:35: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
t = time.clock()
f:\TEST\1.py:40: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
t = time.clock()
100%[**************************************************->]2.59s
林祖泉:-----------执行结束----------
PS F:\TEST>
代码:
import time
scale = 50
print("执行开始".center(scale//2,'-'))
start = time.perf_counter()
for i in range(scale+1):
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
t = time.perf_counter() - start
# print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="\n")
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="")
time.sleep(0.05)
print("\n林祖泉:"+"执行结束".center(scale//2,'-'))
控制台输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS F:\TEST> & 'D:\Python\Python37\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '59643' '--' 'f:\TEST\1.py'
-----------执行开始----------
100%[**************************************************->]2.54s
林祖泉:-----------执行结束----------
PS F:\TEST>
代码:
import time
scale = 50
print("执行开始".center(scale//2,'-'))
start = time.process_time()
for i in range(scale+1):
myList = [item for item in range(1000000)]
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
t = time.process_time() - start
# myList = [item for item in range(10)]
# print(myList)
# print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="\n")
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="")
time.sleep(0.05)
print("\n林祖泉:"+"执行结束".center(scale//2,'-'))
控制台输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS F:\TEST> & 'D:\Python\Python37\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '59658' '--' 'f:\TEST\1.py'
-----------执行开始----------
100%[**************************************************->]5.09s
林祖泉:-----------执行结束----------
PS F:\TEST>
全部代码:
import time
scale = 10
print("------执行开始------")
for i in range(scale+1): # i = 0,1,2,...,9,10
a, b = "**" * i, ".." * (scale - i)
c = (i/scale)*100
print("%{:^4.0f}[{}->{}]".format(c,a,b))
time.sleep(0.1)
print("------执行结束------")
import time
for i in range(101):
print("\r{:3}%".format(i),end="")
time.sleep(0.05)
import time
print("##"*20,end="")
time.sleep(2)
print("\r****")
import time
scale = 50
print("执行开始".center(scale//2,'-'))
t = time.clock()
for i in range(scale+1):
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
t = time.clock()
# print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="\n")
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="")
time.sleep(0.05)
print("\n林祖泉:"+"执行结束".center(scale//2,'-'))
import time
scale = 50
print("执行开始".center(scale//2,'-'))
start = time.perf_counter()
for i in range(scale+1):
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
t = time.perf_counter() - start
# print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="\n")
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="")
time.sleep(0.05)
print("\n林祖泉:"+"执行结束".center(scale//2,'-'))
import time
scale = 50
print("执行开始".center(scale//2,'-'))
start = time.process_time()
for i in range(scale+1):
myList = [item for item in range(1000000)]
a = '*' * i
b = '.' * (scale - i)
c = (i/scale)*100
t = time.process_time() - start
# myList = [item for item in range(10)]
# print(myList)
# print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="\n")
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,t),end="")
time.sleep(0.05)
print("\n林祖泉:"+"执行结束".center(scale//2,'-'))
控制台输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS F:\TEST> & 'D:\Python\Python37\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '59678' '--' 'f:\TEST\1.py'
------执行开始------
% 0 [->....................]
% 10 [**->..................]
% 20 [****->................]
% 30 [******->..............]
% 40 [********->............]
% 50 [**********->..........]
% 60 [************->........]
% 70 [**************->......]
% 80 [****************->....]
% 90 [******************->..]
%100 [********************->]
------执行结束------
****########################################
-----------执行开始----------
f:\TEST\1.py:35: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
t = time.clock()
f:\TEST\1.py:40: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
t = time.clock()
100%[**************************************************->]10.84s
林祖泉:-----------执行结束----------
-----------执行开始----------
100%[**************************************************->]2.52s
林祖泉:-----------执行结束----------
-----------执行开始----------
100%[**************************************************->]5.12s
林祖泉:-----------执行结束----------
PS F:\TEST>