擅长:python、mysql、java
<p>正如@Emyen指出的,问题是你的输入是一个字符串。使用<code>sympify</code>将字符串转换为表达式,或者,更好的方法是使用符号将表达式创建为Python表达式,例如</p>
<pre><code>x = symbols('x')
expr = x**2 + 8*x + 16
</code></pre>
<p>请参阅<a href="https://github.com/sympy/sympy/wiki/Idioms-and-Antipatterns#strings-as-input" rel="nofollow">https://github.com/sympy/sympy/wiki/Idioms-and-Antipatterns#strings-as-input</a>,了解使用字符串而不是表达式是个坏主意的原因。在</p>