码迷,mamicode.com
首页 > 编程语言 > 详细

Python字符串格式化

时间:2015-06-14 18:16:00      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

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‘

 

Python字符串格式化

标签:

原文地址:http://www.cnblogs.com/zxlovenet/p/4575242.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!