--设置字符串格式
>>> x = 0.123456789
>>> print('value : %.2f' % x)
value : 0.12
>>>
>>> x = 0.123456789
>>> y = 0.123456789
>>> print('x = %.2f y = %.3f' % (x, y))
x = 0.12 y = 0.123
>>>
其他函数请查字符串函数
 
--格式化字符串格式
>>> 'My {pet} is {color}'.format (pet = 'dog', color = 'black')
'My dog is black'
>>> 'My {0} is {1}'.format ('dog', 'black')
'My dog is black'
>>>
posted on 2017-02-06 20:11  john2017  阅读(274)  评论(0编辑  收藏  举报