Python | sympy.compare () method

Python Methods and Functions

Using the sympy.compare() method we can compare the variables and it will return 3 values, i.e. -1 for less, 0 for equal and 1 for greater, using sympy.compare () .

Syntax: sympy .compare ()
Return: Return the value of comparison ie -1, 0, 1.

Example No. 1:
In this example we can see that using sympy.compare () we can compare variables and return 3 values, i.e. -1 for less, 0 for equal and 1 for greater.

# import sympy

from sympy import *

x, y = symbols ( 'xy' )

  
# Use the sympy.compare () method

gfg = x.compare (y)

 

print (gfg)

Output:

-1

Example # 2:

# import sympy

from sympy import *

x, y = symbols ( 'xy' )

 
# Use the sympy method. compare ()

gfg = x. compare (x)

 

print (gfg)

Output:

0

Example # 3:

# import sympy

from sympy import *

x, y = symbols ( 'xy' )

  
# Use the sympy.compare () method

gfg = y.compare (x)

 

print (gfg)

Output:

1