zoukankan      html  css  js  c++  java
  • Python-11-字符串格式化_02_Format

     1 test1 = 'I am {name},age {a}'.format(name='newmet', a=15)
     2 print(test1)
     3 test1 = 'I am {name},age {a}'.format(**{"name": 'newmet', "a" : 15})
     4 print(test1)
     5 test1 = 'I am {1},age {0}'.format('newmet', 15)
     6 print(test1)
     7 test1 = 'I am {1},age {1}'.format('newmet', 15)
     8 print(test1)
     9 test1 = "I am {0[0]}, age {0[1]}, really {0[2]}".format([1, 2, 3], [11, 22, 33])
    10 print(test1)
    11 test1 = "I am {:s}, age {:d}, money {:f}".format("seven", 18, 88888.1)
    12 print(test1)        # I am seven, age 18, money 88888.100000
    13 test1 = "I am {:s}, age {:d}".format(*["seven", 18])
    14 print(test1)
    15 test1 = "I am {name:s}, age {age:d}".format(name="seven", age=18)
    16 print(test1)
    17 test1 = "I am {name:s}, age {age:d}".format(**{"name": "seven", "age": 18})
    18 print(test1)
    19 test1 = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(15, 15, 15, 15, 15, 15.87623, 2)
    20 print(test1)        #:b - 二进制  :0 - 八进制  :d - 整型  :x - 小写十六进制  :X - 大写十六进制  :% - 显示百分比
    21 test1 = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(15, 15, 15, 15, 15, 15.87623, 2)
    22 print(test1)            # numbers: 1111,17,15,f,F, 1587.623000%
    23 test1 = "numbers: {0:b},{0:o},{0:d},{0:x},{0:X}, {0:%}".format(15)
    24 print(test1)            # numbers: 1111,17,15,f,F, 1500.000000%
    25 test1 = "numbers: {num:b},{num:o},{num:d},{num:x},{num:X}, {num:%}".format(num=15)
    26 print(test1)            # numbers: 1111,17,15,f,F, 1500.000000%
  • 相关阅读:
    Nginx——基本操作
    JavaWeb——关于RequestDispatcher的原理
    JavaWeb——XML转义符字
    JavaWeb——JSTL 核心标签库使用
    JavaWeb——jsp-config
    URL和URI区别
    Docker入门5------生产力工具docker-compose
    Docker入门4------Dockerfile
    Docker入门3------手动编辑自定义镜像
    Docker入门2------容器container常规操作
  • 原文地址:https://www.cnblogs.com/newmet/p/9946466.html
Copyright © 2011-2022 走看看