码迷,mamicode.com
首页 > 其他好文 > 详细

字符串格式表示实例

时间:2018-12-20 00:02:12      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:please   mat   price   inpu   ade   pre   bsp   orm   put   

# 字符串格式设置实例
# 根据指定的宽度打印格式良好的价格列表

width = int(input(Please enter width:))

price_width = 10
item_width = width -  price_width

header_fmt = {{:{}}}{{:{}}}.format(item_width, price_width)
fmt = {{:{}}}{{:>{}.2f}}.format(item_width, price_width)

print(= * width)
print(header_fmt.format(Item, Price))
print(- * width)
print(fmt.format(Apples, 0.4))
print(fmt.format(Bananas, 0.9))
print(= * width)

 

字符串格式表示实例

标签:please   mat   price   inpu   ade   pre   bsp   orm   put   

原文地址:https://www.cnblogs.com/zijue/p/10146971.html

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