For example, if I run
import sympy
x, y, z = sympy.symbols('x:z')
f = sympy.exp(x + y) - sympy.sqrt(z)
is there any method of f
that I can use to get a list or tuple of sympy.Symbol
objects that the expression contains? I'd rather not have to parse srepr(f)
or parse downward through f.args
.
In this case, g.args[0].args[1].args[0]
gives me Symbol("z")
, while g.args[1].args[0].args
gives me the tuple (Symbol("x"), Symbol("y"))
, but obviously these are expression-specific.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…