zoukankan      html  css  js  c++  java
  • python占位符介绍及操作方法

    1,常用占用符: 

    常见的占位符有:
    %d    整数
    %f    浮点数
    %s    字符串
    %x    十六进制整数
    使用方法:
    tpl = "i am %s" % "alex"
     
     tpl = "i am %s age %d" % ("alex"18)
     
     tpl = "i am %(name)s age %(age)d" % {"name""alex""age"18}
     
     tpl = "percent %.2f" % 99.97623
     
     tpl = "i am %(pp).2f" % {"pp"123.425556, }
     
     tpl = "i am %.2f %%" % {"pp"123.425556, }
     
    2,Format方法
    tpl = "i am {}, age {}, {}".format("seven"18'alex')
      
    tpl = "i am {}, age {}, {}".format(*["seven"18'alex'])
      
    tpl = "i am {0}, age {1}, really {0}".format("seven"18)
      
    tpl = "i am {0}, age {1}, really {0}".format(*["seven"18])
      
    tpl = "i am {name}, age {age}, really {name}".format(name="seven", age=18)
      
    tpl = "i am {name}, age {age}, really {name}".format(**{"name""seven""age"18})
      
    tpl = "i am {0[0]}, age {0[1]}, really {0[2]}".format([123], [112233])
      
    tpl = "i am {:s}, age {:d}, money {:f}".format("seven"1888888.1)
      
    tpl = "i am {:s}, age {:d}".format(*["seven"18])
      
    tpl = "i am {name:s}, age {age:d}".format(name="seven", age=18)
      
    tpl = "i am {name:s}, age {age:d}".format(**{"name""seven""age"18})
     
    tpl = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(151515151515.876232)
     
    tpl = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(151515151515.876232)
     
    tpl = "numbers: {0:b},{0:o},{0:d},{0:x},{0:X}, {0:%}".format(15)
     
    tpl = "numbers: {num:b},{num:o},{num:d},{num:x},{num:X}, {num:%}".format(num=15)
  • 相关阅读:
    codility上的问题(15) Xi 2012
    HDU 4350 Card
    如何在SourceInsight中选中匹配的大括号中的内容
    Codility上的问题 (16) Omicron 2012
    WPF的MVVM
    html5的自定义data-*属性和jquery的data()方法的使用
    hdu 4635 Strongly connected(强连通+缩点)
    HDU3709:Balanced Number(数位DP+记忆化DFS)
    NGUI: Documentation
    Android到您的计算机使用命令行屏幕捕获和出口
  • 原文地址:https://www.cnblogs.com/a389678070/p/9559360.html
Copyright © 2011-2022 走看看