zoukankan      html  css  js  c++  java
  • 七种常见的字符串格式化方法

    1、保留小数点后两位

    >>> print("{:.2f}".format(3.1415))
    3.14

    2、带符号保留小数点后两位

    >>> print("{:+.2f}".format(-3.1415))
    -3.14

    3、不带小数点

    >>> print('{:.0f}'.format(2.7))
    3

    4、整数补零,填充左边, 宽度为3

    >>> print('{:0>3d}'.format(4))
    004

    5、以逗号分隔的数字格式

    >>> print('{:,}'.format(123456789))
    123,456,789

    6、百分比格式

    >>> print('{:.2%}'.format(0.98))
    98.00%

    7、指数记法

    >>> print('{:.2e}'.format(123456789))
    1.23e+08
  • 相关阅读:
    Sword 17
    Sword 16
    Sword 15
    Sword 14-II
    Sword 14-I
    Sword 13
    Sword 11
    Sword 10-II
    Sword 10
    【python+selenium】三种等待方式
  • 原文地址:https://www.cnblogs.com/shiyixirui/p/14313809.html
Copyright © 2011-2022 走看看