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

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

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

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

还可以格式化数字:

 

文章来源:http://www.runoob.com/python/att-string-format.html

posted @ 2021-08-15 23:34  MR__Wang  阅读(74)  评论(0编辑  收藏  举报