{"id":25440,"date":"2021-11-12T14:59:44","date_gmt":"2021-11-12T09:29:44","guid":{"rendered":"https:\/\/python-programs.com\/?p=25440"},"modified":"2021-11-14T15:02:27","modified_gmt":"2021-11-14T09:32:27","slug":"python-cmath-isnan-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-cmath-isnan-method-with-examples\/","title":{"rendered":"Python cmath.isnan() Method with Examples"},"content":{"rendered":"
cmath.isnan() Method in Python:<\/strong><\/p>\n The cmath.isnan() method determines whether a value is a nan (Not a Number).<\/p>\n This method gives the following Boolean value: True if the value is nan, False otherwise.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n x:<\/strong> This is Required. The value used to test for NaN<\/p>\n Return Value:<\/strong><\/p>\n Returns a bool value that is True if any part of a complex number (real or imaginary) is NaN, otherwise False.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Note:<\/strong> The above input format is for dynamic input.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Similarly, try for the other examples<\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n cmath.isnan() Method in Python: The cmath.isnan() method determines whether a value is a nan (Not a Number). This method gives the following Boolean value: True if the value is nan, False otherwise. Syntax: cmath.isnan(x) Parameters x: This is Required. The value used to test for NaN Return Value: Returns a bool value that is True …<\/p>\ncmath.isnan(x)<\/pre>\n
Given Complex Number = 3+4j<\/pre>\n
The result after applying isnan() method to the given complex number (3+4j) = \r\nFalse<\/pre>\n
Given realpart = 5\r\nGiven imaginary part = 2<\/pre>\n
The result after applying isnan() method to the given complex number (5+2j) = \r\nFalse<\/pre>\n
cmath.isnan() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import cmath module(for complex number operations) using the import keyword.\r\nimport cmath\r\n# Give the complex number as static input and store it in a variable.\r\ncomplexnumb = 3+4j\r\n# Pass the given complex number as an argument to the cmath.isnan() method\r\n# that determines whether a given complex number's value is nan (Not a Number)or not.\r\n# Store it in another variable.\r\nrslt = cmath.isnan(complexnumb)\r\n# Print the above result after applying isnan() method to the given complex number.\r\nprint(\"The result after applying isnan() method to the given complex number\", complexnumb,\r\n \" = \")\r\nprint(rslt)\r\n<\/pre>\n
The result after applying isnan() method to the given complex number (3+4j) = \r\nFalse<\/pre>\n
import cmath\r\ncomplexnumb = 10 + float('nan')\r\nrslt = cmath.isnan(complexnumb)\r\nprint(\"The result after applying isnan() method to the given complex number = \")\r\nprint(rslt)\r\n<\/pre>\n
The result after applying isnan() method to the given complex number = \r\nTrue<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import cmath module(for complex number operations) using the import keyword.\r\nimport cmath\r\n# Give the real part and imaginary part of the complex number as user input\r\n# using map(), int(), split().\r\n# Store it in two variables.\r\nrealnumb, imaginarynumb = map(int, input(\r\n 'Enter real part and complex part of the complex number = ').split())\r\n# Using a complex() function convert those two variables into a complex number.\r\ncomplexnumb = complex(realnumb, imaginarynumb)\r\n\r\n# Pass the given complex number as an argument to the cmath.isnan() method\r\n# that determines whether a given complex number's value is nan (Not a Number)\r\n# or not.\r\n# Store it in another variable.\r\nrslt = cmath.isnan(complexnumb)\r\n# Print the above result after applying isnan() method to the given complex number.\r\nprint(\"The result after applying isnan() method to the given complex number\", complexnumb,\r\n \" = \")\r\nprint(rslt)\r\n<\/pre>\n
Enter real part and complex part of the complex number = 5 2\r\nThe result after applying isnan() method to the given complex number (5+2j) = \r\nFalse<\/pre>\n","protected":false},"excerpt":{"rendered":"