• python 3种格式化输出


    1.格式化输出,占位符

    #整型输出%d
    print ('整型 %d'% 10)#整型 10
    
    #输出浮点数,小数点后保留两位有效位数
    print ('浮点数,小数点后保留两位有效位数 %.2f ' % (1.890))#浮点数,小数点后保留两位有效位数 1.89
    
    #输出字符串%s
    print ('字符串 %s' % 'python')
    
    #多个联合输出
    name = "python"
    b = 100
    print("你好%s,你的额度是%d" % (name,b))

    2.格式化输出,format

    #python的内置函数format写法
    print("{1} {0} {1}".format("hello", "world"))  # 设置指定位置,输出结果:'world hello world'
    #冒号后的内容是限定输出字符的格式
    print("你好{0},你的余额是{1:.2f}".format("python",3.1))#你好python,你的余额是3.10
    print("你好{},你的余额是{}".format("python",3.1))#你好python,你的余额是3.1
    print("语言:{name}, 受欢迎程度 {level}".format(name="python", level="****"))

    3.格式化输出,python3.6之后的语法

    #python3.6之后有的语法
    name="python"
    print(f"the languge is : {name}")
  • 相关阅读:
    matplotlib-形状
    matplotlib-区域填充
    C++文件操作
    画数学公式
    文字
    画注释
    Doubango简介-sip
    boost的asio接收单路大数据量udp包的方法
    Boost.Asio基本原理(CSDN也有Markdown了,好开森)
    boot asio 非阻塞同步编程---非阻塞的accept和receive。
  • 原文地址:https://www.cnblogs.com/AntonioSu/p/11978095.html
Copyright © 2020-2023  润新知