我有
形式的字符串 sent="Software Development = 1831".
我想只从字符串中提取单词,即"软件开发"。我如何在Python中提取它。
答案 0 :(得分:2)
您可以尝试split
:
>>> sent="Software Development = 1831"
>>> sent.split("=")[0]
'Software Development '
答案 1 :(得分:1)
>>> str="Software Development = 1831"
>>> str.split()
['Software', 'Development', '=', '1831']
or
>>> str.split("=")
['Software Development ', ' 1831']
答案 2 :(得分:0)
最初,您在' ='之间有空格,因此您的代码应如下所示
sent ="软件开发= 1831"
answer = sent.split(" =")[0] #space = =之前和之后