Python | sympy.factor() method
With the help of 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) |
Output :
(x + y)**2
Example #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
Recommended Posts:
- class method vs static method in Python
- Python | next() method
- Python | set() method
- Python | os.dup() method
- Python PIL | RankFilter() method
- Python | os.access() Method
- Python | isinstance() method
- Python | os.chdir() method
- Python PIL | copy() method
- Python PIL | composite() method
- Python | os.pipe() method
- Python | Tensorflow cos() method
- Python | os.kill() method
- Python | os.WSTOPSIG() method
- Python | sys.getallocatedblocks() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



