python 去掉空格_Python怎么去掉最后的空格

strip()函数 去空格\n\r\t函数的用法

5d1c1a9398f5e105.jpg

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='\t\thello world!!'

'hello world!!'

>>> a = 'hello world!!\r\n'

>>> a.strip()

'hello world!!'

更多Python相关技术文章,请访问Python教程栏目进行学习!

以上就是Python怎么去掉最后的空格的详细内容,更多请关注php中文网其它相关文章!

article_wechat2021.jpg?1111

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值