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')
  • 相关阅读:
    2017年系统架构设计师论文范文
    在SQL Server 2008中执行透明数据加密(转自IT专家网)
    开发笔记
    [置顶] GO-Gin框架快速指南
    [置顶] JS-逆向爬虫
    [置顶] ES篇
    [置顶] GO
    [置顶] 爬虫入狱指南
    [置顶] websocket
    [置顶] Linux篇
  • 原文地址:https://www.cnblogs.com/mada1027/p/11688634.html
Copyright © 2011-2022 走看看