Question

I'm new to sympy and and would like to check if an argument is a sympy integer or of type mul. normally, you could do this using:

if ( isinstance(arg, int):
    // do stuff

I want to do something like:

if( isinstance(arg, Integer):
    // do stuff

or

if( isinstance(arg, sympy.core.mul.Mul):
    // do stuff

Thank you!

Was it helpful?

Solution

What you are doing is correct.

In [14]: from sympy import *

In [15]: a = 2*Symbol('x')

In [16]: isinstance(a, Mul)
Out[16]: True

In [17]: a = 2 + Symbol('x')

In [18]: isinstance(a, Add)
Out[18]: True
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top