The Python cmath.isnan() function verifies whether a value is NaN(Not a Number) or not. This function returns the Boolean value, i.e., True if the value is NaN, otherwise False.
A number "x" is said to be NaN if it doesn't represent a real number and can't be expressed as a finite value, i.e., positive or negative infinity. NaN often arises a result of undefined operations, such as taking the square root of a negative number.
SyntaxFollowing is the basic syntax of the Python cmath.isnan() function −
cmath.isnan(x)Parameters
This function accepts a numeric value as a parameter and redirects the value to be NaN.
Return ValueThis function returns a boolean value which is True is the given number is Nan else it returns False.
Example 1In the below example, we are verifying if the floating point number "20.5" is "NaN" using cmath.isnan() function −
import cmath x = cmath.isnan(20.5) print(x)Output
The output obtained is as follows −
FalseExample 2
Here, we are rectifying if positive infinity is NaN using cmath.isnan() function −
import cmath result = cmath.isnan(float('inf')) print("The result is:",result)Output
Following is the result for the above code −
The result is: FalseExample 3
Now, when we use variable "x" to store NaN. Then this cmath.isnan() function gives positive output.
import cmath x = float('nan') y = cmath.isnan(x) print(y)Output
We will get the output as follows −
TrueExample 4
In the following example, if we are passing string as the input, then this cmath.isnan() function gives TypeError.
import cmath res = cmath.isnan("Welcome to Tutorialspoint") print(res)Output
The result produced is as follows −
Traceback (most recent call last): File "/home/cg/root/86486/main.py", line 2, in res = cmath.isnan("Welcome to Tutorialspoint") TypeError: must be real number, not str
python_modules.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4