求知若饥,虚心若愚

Python字符串格式化

In [1]: "%(name)s is %(age)s" % {"name":"bob", "age": 12}
Out[1]: 'bob is 12'
In [2]: "%s is %s" % ("bob", "13")
Out[2]: 'bob is 13'
In [6]: "{0} is {1}".format("bob", "14")
Out[6]: 'bob is 14'
In [7]: "{name} is {age}".format(name="bob",age="15")
Out[7]: 'bob is 15'

 

posted @ 2015-06-14 16:25  初行  阅读(...)  评论(... 编辑 收藏