zoukankan      html  css  js  c++  java
  • Python print函数参数详解



    官方文档

        print(…)
        print(value, …, sep=’ ‘, end=’ ’, file=sys.stdout, flush=False)
        Prints the values to a stream, or to sys.stdout by default.
        Optional keyword arguments:
        file: a file-like object (stream); defaults to the current sys.stdout.
        sep: string inserted between values, default a space.
        end: string appended after the last value, default a newline.
        flush: whether to forcibly flush the stream.

    参数解析
    value:需要输出的值,可以是多个,用”,”分隔。
    sep:多个输出值之间的间隔,默认为一个空格。
    end:输出语句结束以后附加的字符串,默认是换行(’ ’)。
    file:输出的目标对象,可以是文件也可以是数据流,默认是“sys.stdout”。
    flush:flush值为True或者False,默认为Flase,表示是否立刻将输出语句输出到目标对象。

    演示

    默认:print(value, …, sep=’ ‘, end=’ ’, file=sys.stdout, flush=False)

    >>> print("hello world")
    hello world

        1
        2

    当value有多个:

    >>> print("hello","world")
    hello world

        1
        2

    当sep为”,”

    >>> print("hello","world",sep=",")
    hello,world

        1
        2

    当end为“”

    >>>print("hello","world",end="")
    >>>print("hello","world")
    hello worldhello world

        1
        2
        3

    当file指向test.txt

    test = open("test.txt", "w")
    print("hello","world",sep=" ", file=test)

        1
        2
        3

    此时当前目录下会新建一个test.txt文件里面内容为

    hello
    world

        1
        2

    flush=False
    该参数只有两个选项True or False。
    当flush=False时,输出值会存在缓存,然后在文件被关闭时写入。
    当flush=True时,输出值强制写入文件。
    原文:https://blog.csdn.net/weixin_41939225/article/details/79782793

  • 相关阅读:
    linux 经常使用网络命令
    ExtJS学习--------Ext.Element中其它操作方法学习
    对“使用MyEclipse,写的jsp代码因有汉字而无法保存”问题的解决
    SQL之case when then用法
    SQL之CASE WHEN用法详解[1]
    [SQL case when的两种用法]
    在delphi中生成GUID
    在delphi中生成GUID/自动获取临时表名......
    Delphi中Owner和Parent的区别
    Delphi处理数据网格DBGrid的编辑框 获取还没有提交到数据集的字段文本
  • 原文地址:https://www.cnblogs.com/fmgao-technology/p/9071156.html
Copyright © 2011-2022 走看看