文章詳情頁
聊聊Python中end=和sep=的區別
瀏覽:4日期:2022-06-19 15:00:50
end: 默認是換行,表示兩個字符串最后以什么結尾。
eg: 換行 end='n'
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 = 'n'
print(x, sep=)
sep 用于做打印拼接
print('hello', 'world', sep=':')
打印結果:
hello:world
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。
相關文章:
排行榜
