python 中 format函数

 

001、 格式化数值

>>> "{:.2%}".format(0.123456789)
'12.35%'
>>> "{:.5%}".format(0.123456789)
'12.34568%'
>>> "{:.2}".format(0.123456789)
'0.12'
>>> "{:.5}".format(0.123456789)
'0.12346'

 

 

002、格式化字符串

>>> "{}".format("Python")
'Python'
>>> "xx{}yy".format("Python")
'xxPythonyy'
>>> "xx{}yy".format("kkkk")
'xxkkkkyy'

 

posted @ 2022-11-08 18:47  小鲨鱼2018  阅读(35)  评论(0编辑  收藏  举报