• 字符串拼接


    msg = 'I am my hobby is %s' %'asd'

    多个

    msg = 'I am %s  my hobby is %s' %('asd' ''wer')

    %s  字符串

    %d  整形数字

    %f  浮点数

    保留几位  %.3s 

    保留几位小数  %.2f

    name = ‘Alex’

    age  =  23

    msg = ‘name 是 %s ,年纪是%d’ %(name,age)

    "name is %(name)s ,age is %(age)d" %{'name':'ad','age':23}

    tpl = "1 am {},afe {}".format(1,2)

    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)
  • 相关阅读:
    Spring Cloud Hystrix Dashboard的使用 5.1.3
    Spring Cloud Hystrix 服务容错保护 5.1
    Spring Cloud Ribbon 客户端负载均衡 4.3
    Spring Cloud 如何实现服务间的调用 4.2.3
    hadoop3.1集成yarn ha
    hadoop3.1 hdfs的api使用
    hadoop3.1 ha高可用部署
    hadoop3.1 分布式集群部署
    hadoop3.1伪分布式部署
    KVM(八)使用 libvirt 迁移 QEMU/KVM 虚机和 Nova 虚机
  • 原文地址:https://www.cnblogs.com/goodgoodstudy2018/p/13231100.html
Copyright © 2020-2023  润新知