python 版本:2.7.3
运行平台:macX 10.8
开发工具:IDLE
问题描述
width = input('Please enter width(>10): ')
price_width = 10
item_width = width - price_width
header_format = '%-*s%*s'
item_format = '%-*s%*.2f'
print '=' * width
print header_format % (item_width,'Item',price_width,'Price')
print '-' * width
print item_format % (item_width,'Apples',price_width,0.4)
print item_format % (item_width,'Apples',price_width,0.5)
print item_format % (item_width,'Cantaloupes',price_width,1.92)
print '=' * width
运行结果:
书的结果是对齐的,为什么我这边显示是错乱的,
ps:(刚在windows下运行同样的脚本,发现显示是正常的 - -!)
python格式化输出宽度对齐_python 中 字符串格式化示例 输出格式没有达到指定宽度 求帮忙!...