+

Python | sympy.as_ordered_terms () method

Using the sympy.as_ordered_terms() method, we can get terms ordered by variables using sympy.as_ordered_terms () .

Syntax: sympy.as_ordered_terms ()
Return: Return ordered terms in mathematical expression.

Example # 1:
In this example, we see that with sympy.as_ordered_terms () we can get conditions mathematical expression.

# import sympy

from sympy import *  

 

x, y = symbols ( ` xy` )

 
# Use the sympy.as_ordered_terms () method

gfg = (x * * 2 + 2 * x * y + y * * 2 ) .as_ordered_terms ()

 

print (gfg)

Output:

[x ** 2, 2 * x * y, y ** 2]

Example No. 2:

# import sympy

from sympy import *  

 

x, y = symbols ( ` xy` )

 
# Use the sympy.as_ordered_terms () method

gfg = (y + x ) .as_ordered_terms ()

 

print (gfg)

Exit:

[x, y]

Get Solution for free from DataCamp guru