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

    msg='i am %s my hobby is %s' % ('lhf','alex')
    # #  %代表标识,固定格式  s代表传入的为字符串,该字符串可接受任何类型
    # # %d ,只能接收数字
    print(msg)
    # i am lhf my hobby is alex
    msg='i am %s my hobby is %s' % ('lhf',1)
    msg='i am %s my hobby is %s' % ('lhf',[1,2])
    print(msg)
    # i am lhf my hobby is [1, 2]
    name='lhf'
    age=19
    msg='i am %s my hobby is %s' % (name,age)
    print(msg)
    # i am lhf my hobby is 19
    # %f 打印浮点数,默认保留6位。
    # %.2f 指.后面保留2位,且四舍五入
    tpl = "percent %.2f" % 99.976234444444444444
    print(tpl) # percent 99.98
    # %.2f %% 打印百分比
    tpl = 'percent %.2f %%' % 99.976234444444444444
    print(tpl)  # percent 99.98 %
    # 打印字典:键值对
    tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}
    print(tpl)  # i am alex age 18
    msg='i am %(name)+60s my hobby is alex' %{'name':'lhf'}
    print(msg) # i am                                                          lhf my hobby is alex
    # 以33开头结尾,加颜色
    msg='i am 33[43;1m%(name)+60s33[0m my hobby is alex' %{'name':'lhf'}
    print(msg) # i am                                                          lhf my hobby is alex
    print('root','x','0','0',sep=':') # root:x:0:0
    # print('root'+':'+'x'+':'+'0','0')
  • 相关阅读:
    Angular 学习笔记(四)
    Angular 学习笔记(三)
    Angular 学习笔记(二)
    Angular 学习笔记(一)
    ettercap + driftnet 实现同网段下流量欺骗
    kali 下使用 arpspoof 实现断网攻击
    JavaScript 语句
    vscode配置git及码云
    区块链入门
    C#情怀与未来
  • 原文地址:https://www.cnblogs.com/mada1027/p/11688634.html
Copyright © 2011-2022 走看看