Skip to main content
 首页 » 编程设计

python之python中的切片字符串

2025年05月04日20zlslch

我只想从头开始分割字符串。就像我有一个句子:

"All the best wishes" 

我想得到

"the best wishes" , "best wishes", "wishes". 

任何解决方案,谢谢!

请您参考如下方法:

>>> words 
['All', 'the', 'best', 'wishes'] 
>>> [" ".join(words[i:]) for i in range(len(words))] 
['All the best wishes', 'the best wishes', 'best wishes', 'wishes'] 
>>> [" ".join(words[i:]) for i in range(len(words))][1:] 
['the best wishes', 'best wishes', 'wishes']