python中的sep是什么

python中的sep是什么

这篇文章将为大家详细讲解有关python中的sep是什么,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

全称为Separate意为分开、隔开。

用于print两个元素时自定义间隔符(默认为两个空格)

关键字参数sep是实现分隔符,比如多个参数输出时想要输出中间的分隔字符。

print(1, 2, 3, sep = ',', end = '\r\n')
print(1, 2, 3, sep = ' ', end = '\r\n')

结果输出如下:

1,2,3
1 2 3
print("file\n","abc","bcd","fff\n","poi")
print("-------------")
print("file\n","abc","bcd","fff\n","poi",sep='')
print("-------------")
print("file\n","abc","bcd","fff\n","poi",sep=' ')
print("-------------")

其结果为:

file
 abc bcd fff
poi-------------file
abcbcdfff
poi-------------file
 abc bcd fff
poi-------------

关于python中的sep是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。