您的位置:首页技术文章
文章详情页

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

浏览:3日期:2022-06-19 15:00:50

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 编程
相关文章: