strs = ' I like python ' one = strs.strip() print(one) two = strs.rstrip() print(two)
'I like python', 'I like python'
' I like python', ' I like python'
'I like python', ' I like python'
'I like python', 'I like python '
strip():删除首尾空格;
rstrip():仅删除右空格;
res = 'abc123caabc' print(res.strip('abc'))
res = ' 123 \t' print(res.strip())
Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)或字符序列。
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题