Python print函数使用,


 


 本文链接:https://www.cnblogs.com/zyuanlbj/p/11905405.html


 函数定义

def print(self, *args, sep=' ', end='\n', file=None): # known special case of print
    """
    print(value, ..., sep=' ', end='\n', 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.

  """

函数用法

# 1.用法
print('hello world!')
name = '小白'
print(name)

#2.用法:print(name,age,gender)
age =18
gender ='boy'
print(name,age,gender)  # sep默认的分割是空格

# 3.用法: print(value1,value2,value3,...,sep=' ',end='\n')
print(name,age,gender,sep='-') # sep=‘*’  sep='$'  sep='-'

print() 函数的 flush 参数用于控制输出缓存,该参数一般保持为 False 即可,这样可以获得较好的性能。

相关内容

    暂无相关文章

评论关闭