format()格式化字符串,将占位符替换成内容,举个例子:
1 a = "hello {0} welcome to {1}"
2 a1 = a.format("dlrb", "heilongjiang")
3 print(a1)
输出结果:
hello dlrb welcome to heilongjia
代码中,{0},{1}就是占位符,只能从0开始,format()中从位置0开始依次写入要替换的内容
2024-03-25 23:53:34
format()格式化字符串,将占位符替换成内容,举个例子:
1 a = "hello {0} welcome to {1}"
2 a1 = a.format("dlrb", "heilongjiang")
3 print(a1)
输出结果:
hello dlrb welcome to heilongjia
代码中,{0},{1}就是占位符,只能从0开始,format()中从位置0开始依次写入要替换的内容