Skip to main content
 首页 » 编程设计

python之选择字符串的最后一个字符直到 Python 中的空格

2025年05月04日23kenshinobiy

<分区>

在 Python 中是否有任何有效的方法来选择字符串的最后一个字符直到出现空格?

例如我有以下字符串:

str = 'Hello my name is John' 

我想返回'John'。但如果 str 是:

str = 'Hello my name is Sally' 

我想重新运行“Sally”