Python格式化输出

1.格式化输出字符串

 print("My name is %s" % ("OLIVER"))

2.格式化输出整数

print("The number is %d" % (100))

3.格式化输出小数

print("The number is %f" % (37.12))

3.1格式化输出小数(保留位数)

 print("The number is %.1f" % (37.19))

4.指定占位符宽度

 print("String:%10s Int:%6d Float:%9.3f" % ('QIN',23,78.23415))

4.1指定占位符宽度(左对齐)

 print("String:%-10s Int:%-6d Float:%-9.3f" % ('QIN',23,78.23415))

4.2指定占位符

 print("String:%-10s Int:%06d Float:%-9.3f" % ('QIN',23,78.23415))

5.科学计数法

 

format(0.0000000001,'.2e')

 

posted @ 2016-11-17 16:05  OLIVER_QIN  阅读(484)  评论(0编辑  收藏  举报