Python基础教程:format格式化字符串用途1.format格式化字符串的不同传参方式(1)顺序传参(2)索引传参(3)关键字传参(4)容器类型传参{}用作占位符2.顺序传参示例strvar = "{}对{}进行射击" res = strvar.format("光头强","熊二") print(res) 3.索引传参示例strvar = "{1}给{0}一个平底锅" res = strvar.format("灰太狼","红太狼") print(res) 4.关键字传参示例''' Python学习交流,免费公开课,免费资料,免费答疑,加入QQ群:579817333 ''' strvar = "{who2}给{who1}一个平底锅,灰太狼大喊我会回来的" res = strvar.format(who1 = "灰太狼",who2 = "红太狼") print(res) 5.容器类型传参示例[] () {} strvar = "{0[1]}向{1[1]}扔石头." res = strvar.format(["喜羊羊","懒羊羊","美羊羊"], ("灰太狼","灰太狼")) print(res)