zoukankan      html  css  js  c++  java
  • Python基础教程——3使用字符串

    #字符串格式化示例
    #使用给定的宽度打印格式化后的价格表

    width = input ('Please enter ')

    price_width = 10
    item_width = width - price_width

    head_format = '%-*s%*s'
    format      = '%-*s%*.2f'

    print '=' * width
    print head_format % (item_width,'Item',price_width,'Price')
    print '-' * width

    print format % (item_width,'Apples',price_width,0.4)
    print format % (item_width,'Pears',price_width,0.5)
    print format % (item_width,'Cantaloupes',price_width,1.92)#哈密瓜
    print '=' * width

    >>>
    Please enter 35
    ===================================
    Item                          Price
    -----------------------------------
    Apples                         0.40
    Pears                          0.50
    Cantaloupes                    1.92
    ===================================

  • 相关阅读:
    25号了
    9月特别日程
    26日 晴
    8月22日 出游时间更改
    雷雨过后
    28日 多云
    080826 小雨(补记)
    080822 阴
    27日 晴
    IOS 5 ARC机制 (一)
  • 原文地址:https://www.cnblogs.com/miki/p/3308582.html
Copyright © 2011-2022 走看看