Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
math
infinity
communitycreator

What is math.isinf() in Python?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The math.isinf() function in Python returns True if the value is infinite; otherwise, it returns False. In other words, this function is used to check if the number is infinite or not.

Figure 1 shows the visual representation of the math.isinf() function.

Figure 1: Visual representation of math.isinf() function

The math module is required to use this function.

Syntax

math.isinf(number)

Parameter

This function requires the number as a parameter.

Return value

This function returns True if the value is infinite; otherwise, it returns False.

Example

The following example shows how to use math.isinf() in Python.

import math
#number
print ("math.isinf(4):", math.isinf(4))
print ("math.isinf(3.5):", math.isinf(3.5))
print ("math.isinf(-2.6):", math.isinf(-2.6))
print ("math.isinf(0):", math.isinf(0))
#nan
print ("math.isinf(nan):", math.isinf(float("nan")))
#infinity
print ("math.isinf(inf):", math.isinf(float("inf")))
print ("math.isinf(-inf):", math.isinf(float("-inf")))

RELATED TAGS

python
math
infinity
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring