format的用法

format的用法

print("{:-^20}".format(pow(78,3)))
  • :定义格式
  • ^:据中对齐,不足的用前面的额符号的额填充
  • 20:占据20位
print('{:10s} and {:>10s}'.format('hello','world'))  # 取10位左对齐,取10位右对齐
 print('{} is {:.2f}'.format(1.123,1.123))  # 取2位小数
posted @ 2020-09-15 20:34  小杨的冥想课  阅读(254)  评论(0编辑  收藏  举报