falldog 发表于 2015-12-2 15:59:07

python的format函数

  我们格式化构建字符串可以有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
页: [1]
查看完整版本: python的format函数