文章詳情頁
聊聊Python中end=和sep=的區(qū)別
瀏覽:2日期:2022-06-19 15:00:50
end: 默認是換行,表示兩個字符串最后以什么結(jié)尾。
eg: 換行 end='n'
sep: 默認是空格,表示兩個字符串之間用什么分割。
eg: 空格 sep=' '

補充:python 中的 print(x, end=) 和 print(x, sep=)
print(x, end=)for i in range(10): print(i)
輸出結(jié)果:
0 1 2 3 4 5 6 7 8 9
for i in range(10):
print(i, end=' ')
輸出結(jié)果:
0 1 2 3 4 5 6 7 8 9
參數(shù) end 默認打印換行, 即 end = 'n'
print(x, sep=)
sep 用于做打印拼接
print('hello', 'world', sep=':')
打印結(jié)果:
hello:world
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
排行榜

網(wǎng)公網(wǎng)安備