>> " x-6ren">
gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:33:29 25 4
gpt4 key购买 nike

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

例子:

string = "    xyz     "

desired result : " xyz"

最佳答案

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com