zoukankan      html  css  js  c++  java
  • Python3之format

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    print('{0},{1}'.format('zhangk'32))
     
    print('{},{},{}'.format('zhangk','boy',32))
     
    print('{name},{sex},{age}'.format(age=32,sex='male',name='zhangk'))
     
    # 格式限定符
    # 它有着丰富的的“格式限定符”(语法是{}中带:号),比如:
     
    # 填充与对齐
    # 填充常跟对齐一起使用
    # ^、<、>分别是居中、左对齐、右对齐,后面带宽度
    # :号后面带填充的字符,只能是一个字符,不指定的话默认是用空格填充
     
    print('{:>8}'.format('zhang'))
    print('{:0>8}'.format('zhang'))
    print('{:a<8}'.format('zhang'))
    print('{:p^10}'.format('zhang'))
     
    # 精度与类型f
    # 精度常跟类型f一起使用
    print('{:.2f}'.format(31.31412))
     
    # 其他类型
    # 主要就是进制了,b、d、o、x分别是二进制、十进制、八进制、十六进制
    print('{:b}'.format(15))
     
    print('{:d}'.format(15))
     
    print('{:o}'.format(15))
     
    print('{:x}'.format(15))
     
    # 用逗号还能用来做金额的千位分隔符
    print('{:,}'.format(123456789))

      

  • 相关阅读:
    响应式设计
    Flex box 弹性盒子布局
    下拉菜单  -
    html使用技巧
    nth-of-type(n)
    Js中 关于top、clientTop、scrollTop、offsetTop
    仿iPhone滑屏操作
    网页超过一页 点击回到顶部
    linux svn使用
    Linux查看CPU和内存使用情况
  • 原文地址:https://www.cnblogs.com/pscc/p/9563940.html
Copyright © 2011-2022 走看看