使用re(regex) 执行此模式查找内容,并用于input获取输入的文本:import rea=input('Enter your stuff: ')s=re.sub('[a-zA-Z^]','',a)print([int('-'+i[0]) if s[s.index(i)-2]=='-' else int(i[0]) for i in re.split(' [+|-] ',s)])示例输出:Enter your stuff: 2x^3 + 5x^2 - 8x + 3[2, 5, -8, 3]