zoukankan      html  css  js  c++  java
  • 字符串格式化 format字符串格式化

    #字符串格式化
    msg = 'I am %s ,my hobby is running.' %'Eileen'
    print(msg)

    msg1 ='I am %s,my hobby is %s.' %('Eileen','running')
    print(msg1)
    msg2 = 'I am %s, i am %d year old' %('Eileen',10)
    print(msg2)
    num = 'prcent %f' %0.989878
    num1 = 'prcent %.2f%%' %0.989878
    print(num)
    print(num1)
    msg5 = '【易通航】,您乘坐的%(date)s%(flight)s的航班马上就要起飞了'%{'date':'2020-05-10','flight':'CA112'}
    print(msg5)
    print('192','1','1','1',sep=':')

    #format字符串格式化
    tpl = 'I am {},age {},from {}.'.format('alex',18,'China')
    print(tpl)
    tpl = 'I am {2},age {1},from {0}.'.format('alex',18,'China')
    print(tpl)
    tpl = 'I am {name},age {age},from {country}.'.format(name ='alex',age = 18,country = 'China')
    print(tpl)
    tpl = 'I am {name},age {age},from {country}.'.format(**{'name' :'alex','age' : 18,'country' : 'China'})
    print(tpl)
    tpl = 'I am {1[0]},age {0[1]},from {0[0]}.'.format([1,2,3],[4,5,6])
    print(tpl)
    tpl = 'I am {:s},age {:d},from {:s}.'.format('alex',18,'China')
    print(tpl)
  • 相关阅读:
    3.1按钮
    2.1线性布局
    2.2相对布局
    1.4Activity保存现场状态
    1.1Activity跳转与传值
    1.2Activity返回值
    1.3Activity生命周期
    WebSocket
    Jms消费者模式
    课堂实践5-31
  • 原文地址:https://www.cnblogs.com/lqcjlu/p/12867620.html
Copyright © 2011-2022 走看看