• 格式化


    % 格式

    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, }
     
    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)
  • 相关阅读:
    resin网站出错!
    Java的编译与执行
    对SDK、JDK、JRE和JVM的理解总结
    第一个JDBC实例 操作MYSQL数据库
    三种定义JavaScript函数方法以及使用匿名函数打造自己的类库
    JavaScript 闭包原理和闭包实现
    学习Java运算符时的取余(%)和自加减(++、)的小结
    chmod 命令用法
    Eclipse快捷键大全
    ||运算符在JavaScript的另类用法
  • 原文地址:https://www.cnblogs.com/huangguabushihaogua/p/9364936.html
Copyright © 2020-2023  润新知