-3

In Python, the math.isfinite function returns True if the argument passed is a finite number. I want to know expression or equation (equation that generates infinite value) which will return False, other than 'NAN'. Passing a number divided by 0 will give error.

PARVATHY
  • 122
  • 9

2 Answers2

2

Before asking a question like this, you should always read the documentation. Simply using help(math.isfinite) in a REPL would tell you what values return False.

Help on built-in function isfinite in module math:

isfinite(...)
    isfinite(x) -> bool

    Return True if x is neither an infinity nor a NaN, and False otherwise.

Like Martijn Peters mentioned, float('inf') and float('-inf') will both produce infinite values. And in Python 3.5+, you also have math.inf as a way to produce those values.

Edward Minnix
  • 2,889
  • 1
  • 13
  • 26
  • I would like know a valid equation or expression which generates infinite value and results this function to return false. – PARVATHY Aug 09 '18 at 16:26
1

If you want to create value of infinity you should use

float('inf') # positive infinity 

These value below are all False

import math
math.isfinite(float('inf'))
math.isfinite(float('-inf'))
math.isfinite(float('nan'))
James Liu
  • 497
  • 3
  • 8