Python sympy.is_nonegative()方法
在simpy模块中,我们可以用sympy.is_nonegative()函数测试给定的数字n是否为非负数。
语法: sympy.is_nonnegative(n)
参数 : n; 待测数
返回: bool value result
代码 #1:
# 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)
输出:
False
True
代码 #2:
# Python program to check nonnegative number
# using sympy.is_nonnegative() method
# importing sympy module
from sympy import *
# calling is_negative function on different numbers
geek = simplify(-002).is_nonnegative
print(geek)
输出:
False