On Fri, Sep 16, 2022 at 3:37 PM Yang Liu <
mica...@gmail.com> wrote:
>
> Hi Aron,
>
> Many thanks for your answers. I previously use say f.args[0] to access input like \nabla*f to check. But has() is more error free.
>
> Is there any more robust way to get the specific args symbol? For instance, if the input is like (expr=x*y*z). But I want to get the x from this expression. I would say expr.arg[0]. But if I change the expression order. This doesn't work.
expr.free_symbols will give you a set of all the symbols in an
expression. Does that give you what you need?
If not, I'm not clear what you mean by "the x from this expression".
Note that if you just want a symbol named "x" you can create another
one with Symbol('x'). SymPy treats any two symbols with the same name
and assumptions as equal, so recreating a symbol with the same name is
equivalent to reusing the same symbol object.
Aaron Meurer
> To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/4fe989e9-6104-4026-a3e1-4d112a07f3bfn%40googlegroups.com.