格式化字符串

出了常见的 %s %d进行占位以外

1.format py2.6以后添加
替换字段直接用大括号

通过大括号 + 索引引用变量

使用键值对的方式

  1. f-strings py3.6以后添加
    在字符串之前直接加上'f' 大括号就可以直接使用变量

还可以进行内联运算,在大括号中直接写算术表达式

直接调用函数

官方文档
https://docs.python.org/3/reference/lexical_analysis.html#f-strings

两个花括号

'{{{}}}'.format(function_id)

菜鸟驿站的format教程
https://www.runoob.com/python/att-string-format.html

原文地址:https://www.cnblogs.com/cizao/p/11846084.html