With the help of
Python3 1=1
Output :
Python3 1=1
sympy.factor() method, we can find the factors of mathematical expressions in the form of variables by using sympy.factor() method.
Syntax : sympy.factor(expression)
Return : Return factor of mathematical expression.
Example #1 :
In this example we can see that by using sympy.factor() method, we can find the factors of mathematical expression with variables. Here we use symbols() method also to declare a variable as symbol.
# import sympy
from sympy import expand, symbols, factor
x, y = symbols('x y')
gfg_exp = x + y
exp = sympy.expand(gfg_exp**2)
# Use sympy.factor() method
fact = factor(exp)
print(fact)
(x + y)**2Example #2 :
# import sympy
from sympy import expand, symbols, factor
x, y, z = symbols('x y z')
gfg_exp = x + y + z
exp = sympy.expand(gfg_exp**2)
# Use sympy.factor() method
fact = factor(exp)
print(fact)
Output :
(x + y + z)**2