python - 如何从 Python 中的字符串末尾删除空格?

标签 python

我需要删除字符串中单词后的空格。这可以在一行代码中完成吗?

例子:

string = "    xyz     "

desired result : "    xyz" 

最佳答案

>>> "    xyz     ".rstrip()
'    xyz'

the documentation 中有更多关于 rstrip 的内容.

关于python - 如何从 Python 中的字符串末尾删除空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2372573/

相关文章:

python - 在请求中设置端口

python - 访问 pyModbus 事务中的原始字节

Python - 以表格格式写入文件

python - 将 pandas datetimeindex 延长 1 个周期

python - 列表中包含的元组和字典

python - 使用try语句,但给我语法错误

python - 使正则表达式适应 python re 模块

python - 错误 "AttributeError: ' Py4JError'对象没有属性 'message'构建DecisionTreeModel

python - 即使已经安装,也无法在 Jupyter 中导入 statsmodels?

python - Python 中新旧三元条件运算符的不同结果