我们格式化构建字符串可以有3种方法:
1 元组占位符
m = ‘python‘
astr = ‘i love %s‘ % m
print astr
2 字符串的format方法
m = ‘python‘
astr = "i love {python}".format(python=m)
print astr
3 字典格式化字符串
m = ‘python‘
astr = "i love %(python)s " % {‘python‘:m}
print astr
时间: 2024-11-06 21:43:34