关于python占位符数字补0

%格式化
  print('%2d-%02d-%.2f' % (3, 1, 2.113))
  输出 :' 3-01-2.11'

format()格式化
  print("{0:2d}-{1:02d}-{2:.2f}-{3:0<4d}".format(1, 5, 6, 7))
  输出:' 1-05-6.00-7000'
  
  print("{0}{1:0>2d}{2:0>2d}{3:0>2d}".format(*time.localtime()))

f-sting()
r=2.5
s=3.14*r
  print(f'The area of a circle with radius {r} is {s:.2f}')
  输入:
The area of a circle with radius 2.5 is 19.62
 
posted @ 2021-09-02 13:52  umsung  阅读(373)  评论(0)    收藏  举报