python中的format

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开始依次写入要替换的内容

原文地址:https://www.cnblogs.com/xwqhl/p/10675249.html