Open In App

Python | sympy.is_nonnegative() method

Last Updated : 08 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In sympy module, we can test whether a given number n is non-negative or not using sympy.is_nonnegative() function.

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

Code #1: 

Python3




# Python program to check nonnegative number
# using sympy.is_nonnegative() method
 
# importing sympy module
from sympy import *
 
# calling is_nonnegative function on different numbers
geek1 = simplify(-21).is_nonnegative
geek2 = simplify(0).is_nonnegative
 
print(geek1)
print(geek2)


Output: 

False
True

Code #2: 

Python3




# Python program to check nonnegative number
# using sympy.is_nonnegative() method
 
# importing sympy module
from sympy import *
 
# calling is_negative function on different numbers
geek1 = simplify(-0.2).is_nonnegative
geek2 = simplify(45/8).is_nonnegative
 
print(geek1)
print(geek2)


Output: 

False
True

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads