python去空格的函数_Python怎么去掉最后的空格
strip()函數 去空格nrt函數的用法
strip 同時去掉左右兩邊的空格(推薦學習:Python視頻教程)
lstrip 去掉左邊的空格
rstrip 去掉右邊的空格
具體示例如下:>>>a=" hello world!! "
>>>a.lstrip() 'hello world!! '
>>>a.rstrip() ' hello world!!'
>>>a.strip() 'hello world!!'
聲明:s為字符串,rm為要刪除的字符序列
s.strip(rm) 刪除s字符串中開頭、結尾處,位于 rm刪除序列的字符
s.lstrip(rm) 刪除s字符串中開頭處,位于 rm刪除序列的字符
s.rstrip(rm) 刪除s字符串中結尾處,位于 rm刪除序列的字符
注意:
當rm為空時,默認刪除空白符(包括’n’, ‘r’, ‘t’, ’ ')>>> a = ' hello world!!'
>>> a.strip()
'hello world!!'
>>> a='tthello world!!'
'hello world!!'
>>> a = 'hello world!!rn'
>>> a.strip()
'hello world!!'
更多Python相關技術文章,請訪問Python教程欄目進行學習!
以上就是小編分享的關于Python怎么去掉最后的空格的詳細內容希望對大家有所幫助,更多有關python教程請關注環球青藤其它相關文章!
總結
以上是生活随笔為你收集整理的python去空格的函数_Python怎么去掉最后的空格的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前金立高管俞雷成立新手机品牌:名为“Fr
- 下一篇: python定时发送信息_python实