strip()函数 去空格\n\r\t函数的用法
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怎样去掉最初的空格的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!