Python程序错误记录
1. ValueError: Unknown format code ‘f’ for object of type ‘str’
示例:
import time
scale=10
print("程序210开始".center(50,'-'))
t=time.perf_counter()
for i in range(scale+1):
a='*'*i
b='·'*(scale-i)
c=(i/scale)*100
t-=time.perf_counter()
print("\r{:^3.0f}%[{}->]{:.2f}s".format(c,a,b,-t),end='')
time.sleep(0.5)
print("程序结束".center(50,'-'))
- 以上代码将提示第10行发生错误,错误原因即占位槽{}不匹配导致。
print(“\r{:^3.0f}%[{}->]{:.2f}s”.format(c,a,b,-t),end=‘’)
print(“\r{:^3.0f}%[{}->{}]{:.2f}s”.format(c,a,b,-t),end=’ ')