+

Python | sympy.is_negative () method

In the simpy module, we can check if a given number n is negative or not using sympy.is_negative () .

  Syntax:  sympy .is_negative (n)  Parameter:  n; number to be tested  Return:  bool value result 

Code # 1:

# Python program to check for negative numbers
# using sympy.is_negative () method

  
# import sympy module

from sympy import *

 
# calling the is_negative function for different numbers

geek1 = simplify ( - 21 ). is_negative

geek2 = simplify ( 0 ). is_negative

 

print (geek1)

print (geek2)

Exit:

 True False 

Code # 2:

# Python program to test for negative numbers
# using sympy.is_negative () method

 
# sympy module import

from sympy import *

 
# call in is_negative function for different numbers

geek = simplify ( - 002 ). is_negative

 

print (geek)

Output:

 True                                        
             
                
Get Solution for free from DataCamp guru