Python字符串替换占位符

s = "{0}-{1},{2}".format("zhang", 2018, 2019)
print(s)

s = "{name},{year}-{net}".format(name="phil", year=2019, net="blog.csdn.net")
print(s)

s = "{name},{0}".format(2019, name="zhangphil")
print(s)


运行输出:

zhang-2018,2019
phil,2019-blog.csdn.net
zhangphil,2019
发布了1029 篇原创文章 · 获赞 987 · 访问量 336万+

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/89460851