zoukankan      html  css  js  c++  java
  • python 第三章 字符串-例1

    1.字段宽度和精度

    >>>'%.*s' % (10,'Gruido')

    '     Guido'

    >>>'%.-*s' % (10,'Gruido')

    'Guido     '

    详见例子

    width = input('Please enter ')
    price_width=10
    item_width=width-price_width

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

    print '=' * width

    print header_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 format %(item_width,'Dried Apricots(16 oz.)',price_width,8)
    print format %(item_width,'Prunes(4 1bs.)',price_width,12)

    输出结果:

    Please enter width:35

    ===================================

    Item                       Price

    -------------------------------------------------------

    Apples                      0.4

    ...                         ...

    ...                         ...

    ...                         ...

    ...                         ...

    ...                         ...

    ===================================

  • 相关阅读:
    判断进程是64bit还是32bit
    判断是否是64位系统(之前那个是判断是否是64位进程不一样。注意区分)
    以程序的方式操纵NTFS的文件权限
    Windows平台内核级文件访问
    TLSAlloc()
    Android开发效率的小技巧
    二分查找法
    unittest 框架
    ASP.NET MVC中使用Ninject
    Java内存区域与内存溢出异常
  • 原文地址:https://www.cnblogs.com/yhcreak/p/5327931.html
Copyright © 2011-2022 走看看