Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能。

基本语法是通过 {} 和 : 来代替以前的 % 。

format 函数可以接受不限个参数,位置可以不按顺序。

Python print  format() 格式化内置函数

Python print  format() 格式化内置函数

还可以格式化数字:

Python print  format() 格式化内置函数

 

 

详细介绍:http://www.runoob.com/python/att-string-format.html

相关文章:

  • 2021-11-12
  • 2022-01-15
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-30
  • 2021-06-29
  • 2022-12-23
相关资源
相似解决方案