如何从python中的字符串中提取单词?

How to extract words from the string in python?

本问题已经有最佳答案,请猛点这里访问。

我有一系列的表格

1
 sent="Software Development = 1831".

我只想从字符串中提取单词,即"软件开发"。如何用Python提取这个。


您可以尝试split

1
2
3
>>> sent="Software Development = 1831"
>>> sent.split("=")[0]
'Software Development '


1
2
3
4
5
6
7
8
9
>>> str="Software Development = 1831"

>>> str.split()
['Software', 'Development', '=', '1831']

or

>>> str.split("=")
['Software Development ', ' 1831']


最初,您在"="之间有空格,因此您的代码应该如下所示。

sent="Software Development = 1831"

answer=sent.split(" =")[0] #space before and after =