我是靠谱客的博主 任性板凳,这篇文章主要介绍print()函数,现在分享给大家,希望可以做个参考。

python中最常用的函数便是print(),这个函数很好用。

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.
    """
    pass
a = 1
b = 2

print(a)
print(b)

1
2

这里输出a和b的变量值,1之后2进行了换行,因为print函数中默认的 end=’n’ 结束是以换行符结束的。我们修改 结束标识

print(a, end='')
print(b)

12

a和b的变量输出就没有换行了。

*args 表名一次可以输出多个变量,中间用逗号分隔即可。

print(a, b)

1 2

根据上面的参数 sep=’ ',默认参数之间的分隔符就是 空白字符串,可以设置这个分隔符

print(a, b, sep="")

12

最后

以上就是任性板凳最近收集整理的关于print()函数的全部内容,更多相关print()函数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(96)

评论列表共有 0 条评论

立即
投稿
返回
顶部