美文网首页
Python 去除字符串前后空格

Python 去除字符串前后空格

作者: zzl灬 | 来源:发表于2020-08-27 14:33 被阅读0次
strip_test_string=' 1 23 '
strip_test = strip_test_string.strip()       #去除字符串前后空格
print '-'+strip_test+'-'
lstrip_test = strip_test_string.lstrip()     #去除字符串前面的空格
print '-'+lstrip_test+'-'
rstrip_test = strip_test_string.rstrip()     #去除字符串后面的空格
print '-'+rstrip_test+'-'

运行结果

结果.png

相关文章

网友评论

      本文标题:Python 去除字符串前后空格

      本文链接:https://www.haomeiwen.com/subject/ihmcsktx.html