Python study -格式化字符串

Python study -格式化字符串

字符串格式化与字符串连接的比较

>>>count =6
>>>print "count is %d" % (count,)
count is 6
>>>
print "count is %s" % (count,)
count is 6
>>>
print "count is %f" % (count,)
count is 6.000000
>>>
print "count is %.2f" % (count,)
count is 6.00
>>>
print "count is " +count
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects



你可能感兴趣的:(Python study -格式化字符串)