In sympy module, we can test whether a given number n is negative or not using sympy.is_negative() function.
Syntax: sympy.is_negative(n) Parameter: n; number to be tested Return: bool value result
Code #1:
Python3
# Python program to check negative number # using sympy.is_negative() method# importing sympy modulefrom sympy import *# calling is_negative function on different numbersgeek1 = simplify(-21).is_negativegeek2 = simplify(0).is_negativeprint(geek1)print(geek2) |
Output:
True False
Code #2:
Python3
# Python program to check negative number # using sympy.is_negative() method# importing sympy modulefrom sympy import *# calling is_negative function on different numbersgeek1 = simplify(-0.2).is_negativegeek2 = simplify(2).is_negativeprint(geek1)print(geek2) |
Output:
True False
