zoukankan      html  css  js  c++  java
  • python format格式化进阶-左对齐右对齐 取位数

    (1)< (默认)左对齐、> 右对齐、^ 中间对齐、= (只用于数字)在小数点后进行补齐

    (2)取位数“{:4s}”、"{:.2f}"等

    1 >>> print('{} and {}'.format('hello','world'))  # 默认左对齐
    2 hello and world
    3 >>> print('{:10s} and {:>10s}'.format('hello','world'))  # 取10位左对齐,取10位右对齐
    4 hello      and      world
    5 >>> print('{:^10s} and {:^10s}'.format('hello','world'))  # 取10位中间对齐
    6   hello    and   world  
    7 >>> print('{} is {:.2f}'.format(1.123,1.123))  # 取2位小数
    8 1.123 is 1.12
    9 >>> print('{0} is {0:>10.2f}'.format(1.123))  # 取2位小数,右对齐,取10位
    10 1.123 is       1.12

  • 相关阅读:
    如何开启无线网卡
    E-SATA接口
    sata express接口
    联想服务器驱动
    国家信息安全漏洞共享平台
    SQL SERVER 性能调优
    计算机网络知识库
    CCNP 视频
    ORACLE 培训 -相克军
    phxsql
  • 原文地址:https://www.cnblogs.com/nuonuozhou/p/11298374.html
Copyright © 2011-2022 走看看