Python | sympy.expand() method
With the help of sympy.expand() method, we can expand the mathematical expressions in the form of variables by using sympy.expand() method.
Syntax :
sympy.expand(expression)
Return : Return mathematical expression.
Example #1 :
In this example we can see that by using sympy.expand() method, we can get the mathematical expression with variables. Here we use symbols() method also to declare a variable as symbol.
# import sympy from sympy import expand, symbols x, y = symbols('x y') gfg_exp = x + y # Use sympy.expand() method exp = sympy.expand(gfg_exp**2) print(exp) |
Output :
x**2 + 2*x*y + y**2
Example #2 :
# import sympy from sympy import expand, symbols x, y, z = symbols('x y z') gfg_exp = x + y + z # Use sympy.expand() method exp = sympy.expand(gfg_exp**2) print(exp) |
Output :
x**2 + 2*x*y + 2*x*z + y**2 + 2*y*z + z**2
Recommended Posts:
- class method vs static method in Python
- Python | set() method
- Python | os.dup() method
- Python | next() method
- Python | os.pread() method
- Python | os.fsencode() method
- Python | os.isatty() method
- Python | os.device_encoding() method
- Python | setattr() method
- Python | os.system() method
- Python | os.sched_rr_get_interval() method
- Python | Decimal ln() method
- Python | os._exit() method
- Python | os.WEXITSTATUS() method
- Python | os.abort() 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.



