聊聊Python中end=和sep=的区别

2021-07-04 0 991

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

eg: 换行 end=\”\\n\”

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

eg: 空格 sep=\” \”

聊聊Python中end=和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 = \”\\n\”

print(x, sep=)

sep 用于做打印拼接

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

打印结果:

hello:world

以上为个人经验,希望能给大家一个参考,也希望大家多多支持自学编程网。

遇见资源网 Python 聊聊Python中end=和sep=的区别 http://www.ox520.com/28809.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务