Python | sympy.compare() method
Last Updated :
19 Jul, 2019
With the help of sympy.compare()
method, we can compare the variables and it will return 3 values i.e -1 for smaller, 0 for equal and 1 for greater by using sympy.compare()
method.
Syntax : sympy.compare()
Return : Return the value of comparison i.e -1, 0, 1.
Example #1 :
In this example we can see that by using sympy.compare()
method, we are able to compare the variables and return 3 values i.e -1 for smaller, 0 for equal and 1 for greater.
from sympy import *
x, y = symbols( 'x y' )
gfg = x.compare(y)
print (gfg)
|
Output :
-1
Example #2 :
from sympy import *
x, y = symbols( 'x y' )
gfg = x.compare(x)
print (gfg)
|
Output :
0
Example #3 :
from sympy import *
x, y = symbols( 'x y' )
gfg = y.compare(x)
print (gfg)
|
Output :
1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...