python
主页 > 脚本 > python >

Python中end=和sep=的区别

2021-05-17 | 秩名 | 点击:

end: 默认是换行,表示两个字符串最后以什么结尾。

eg: 换行 end=" "

sep: 默认是空格,表示两个字符串之间用什么分割。

eg: 空格 sep=" "

补充:python 中的 print(x, end=) 和 print(x, sep=)

print(x, end=)
for i in range(10):
    print(i)

输出结果:

0 1 2 3 4 5 6 7 8 9

for i in range(10):

print(i, end=" ")

输出结果:

0 1 2 3 4 5 6 7 8 9

参数 end 默认打印换行, 即 end = " "

print(x, sep=)

sep 用于做打印拼接

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

打印结果:

hello:world

原文链接:https://blog.csdn.net/weixin_44675380/article/details/87967032
相关文章
最新更新