python中的format

it2026-05-04  7

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

posted on 2019-04-09 10:14 恒笛 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/xwqhl/p/10675249.html

相关资源:数据结构—成绩单生成器
最新回复(0)