字符串格式表示实例

Posted zijue

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串格式表示实例相关的知识,希望对你有一定的参考价值。

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

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)

 

以上是关于字符串格式表示实例的主要内容,如果未能解决你的问题,请参考以下文章