zoukankan      html  css  js  c++  java
  • python的print函数的格式化输出

    使用print函数的时候,可以像C一样格式化输出,同时还支持参数化输出

    print('%s' % ("CooMark"))
    print('整数|%d|' % (123))
    print('浮点数|%f|' % (123))
    print('保留两位小数|%.2f|' % (123))
    print('指定总宽度和小数位数|%8.2f|' % (123))
    print('指定总宽度并且左对齐|%-8.2f|' % (123))
    print('指定总宽度和用0占位|%08.2f|' % (123))
    print('科学计数法|', format(0.0015, '.2e'), '|')
    print('参数化输出|{0} is already {1} years old...|'.format('CooMark', 30))
    
    # CooMark
    # 整数|123|
    # 浮点数|123.000000|
    # 保留两位小数|123.00|
    # 指定总宽度和小数位数|  123.00|
    # 指定总宽度并且左对齐|123.00  |
    # 指定总宽度和用0占位|00123.00|
    # 科学计数法| 1.50e-03 |
    # 参数化输出|CooMark is already 30 years old...|
    # [Finished in 0.9s]
    
  • 相关阅读:
    bfs,队列
    Wannafly挑战赛22 A计数器(裴蜀定理 gcd)
    素数筛模板
    HDU
    HDU
    控制精度-----直接截取,不需四舍五入
    jstl下载与配置
    B. Treasure Hunt
    动态数组vector
    Manacher算法
  • 原文地址:https://www.cnblogs.com/wancy86/p/print_format.html
Copyright © 2011-2022 走看看