{"id":24192,"date":"2021-10-14T09:17:19","date_gmt":"2021-10-14T03:47:19","guid":{"rendered":"https:\/\/python-programs.com\/?p=24192"},"modified":"2021-11-05T20:54:32","modified_gmt":"2021-11-05T15:24:32","slug":"python-program-for-isinf-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-isinf-function\/","title":{"rendered":"Python Program for isinf() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for How To Find Cube Root<\/a> The math.isinf() method determines whether or not a number is infinite.<\/p>\n If the specified number is positive or negative infinity, this method returns true; otherwise, it returns False.<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong><\/p>\n x: <\/strong>This is required. It is a number to check.<\/p>\n Return Value: <\/strong>It returns a boolean value. If x is positive or negative infinity, this statement is true. 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 Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Read all the mathematical functions available in Python and understand how to implement them in your program by using the tutorial of Python Mathematical Methods Examples<\/a>.<\/p>\n In the previous article, we have discussed Python Program for How To Find Cube Root isinf() Function in Python: The math.isinf() method determines whether or not a number is infinite. If the specified number is positive or negative infinity, this method returns true; otherwise, it returns False. Syntax: math.isinf(x) Parameters: x: This is required. It …<\/p>\n
\nisinf() Function in Python:<\/strong><\/p>\nmath.isinf(x)<\/pre>\n
Given value = 1000\r\nGiven value = -100\r\nGiven value = math.pi\r\nGiven value = nan\r\nGiven value = inf\r\nGiven value = -inf<\/pre>\n
False\r\nFalse\r\nFalse\r\nFalse\r\nTrue\r\nTrue<\/pre>\n
Given value = -70000\r\nGiven value = NaN<\/pre>\n
False\r\nFalse<\/pre>\n
Program for isinf() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number as static input and store it in a variable.\r\ngvn_numb = 1000\r\n# Apply math.isinf() function to the given number to check if the given number\r\n# is infinite or not.\r\n# Store it in another variable.\r\nrslt = math.isinf(gvn_numb)\r\n# print the above result.\r\nprint(\"Checking if the above given number\",\r\n gvn_numb, \"is infinite or not :\", rslt)\r\n# similarly check for the other values and print the result.\r\nprint(math.isinf(-100))\r\nprint(math.isinf(math.pi))\r\nprint(math.isinf(float('nan')))\r\nprint(math.isinf(float('inf')))\r\nprint(math.isinf(float('-inf')))\r\n<\/pre>\n
Checking if the above given number 1000 is infinite or not : False\r\nFalse\r\nFalse\r\nFalse\r\nTrue\r\nTrue<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number as user input using the int(input()) function and store it in a variable.\r\ngvn_numb = int(input('Enter some random number = '))\r\n# Apply math.isinf() function to the given number to check if the given number\r\n# is infinite or not.\r\n# Store it in another variable.\r\nrslt = math.isinf(gvn_numb)\r\n# print the above result.\r\nprint(\"Checking if the above given number\",\r\n gvn_numb, \"is infinite or not :\", rslt)\r\n# similarly check for the other values\r\nb = input('Enter some random value = ')\r\nprint(math.isinf(float(b)))<\/pre>\n
Enter some random number = -9999\r\nChecking if the above given number -9999 is infinite or not : False\r\nEnter some random value = inf\r\nTrue<\/pre>\n
\n