Python | sympy.as_terms() method

With the help of sympy.as_terms() method, we can get the mathematical expression as a list of terms by using sympy.as_terms() method.

Syntax : sympy.as_terms()
Return : Return list of terms that are in mathematical expression.

Example #1 :
In this example we can see that by using sympy.as_terms() method, we are able to get the terms of mathematical expression in a list.

 # import sympy from sympy import *     x, y = symbols('x y')    # Use sympy.as_terms() method gfg = (x**2 + 2 * x*y + y**2).as_terms()      print(gfg)

Output :

([(x**2, ((1.0, 0.0), (2, 0), ())), (y**2, ((1.0, 0.0), (0, 2), ())), (2*x*y, ((2.0, 0.0), (1, 1), ()))], [x, y])

Example #2 :

 # import sympy from sympy import *     x, y = symbols('x y')    # Use sympy.as_terms() method gfg = (y + x).as_terms()      print(gfg)

Output :

([(x, ((1.0, 0.0), (1, 0), ())), (y, ((1.0, 0.0), (0, 1), ()))], [x, y])

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.