Python cmath.isfinite() Function



The Python cmath.isfinite() function verifies whether the number is finite or not.

This function returns True if the specified number is finite number; otherwise, it returns False. In this function, a floating point is considered finite if it is positive or negative.

For instance, if we have a floating-point, number (x= 3.14), then this function will return True because x is a finite number.

Syntax

Following is the basic syntax of the Python cmath.isfinite() function −

cmath.isfinite(x)

Parameters

This function checks whether the given number is finite or not, this function also accepts a numeric value as a parameter.

Return Value

This function returns a boolean value i.e True or False.

Example 1

In the following example we are checking boolean values for the given complex numbers using cmath.isfinite() function.

import cmath
x = cmath.isfinite(10+3j)
print(x)

Output

Following is the output of the above code −

True

Example 2

Here, we are check if infinite is a finite floating point using cmath.isfinite() function.

import cmath
x = cmath.isfinite(float('inf'))
print(x)

Output

The output obtained is as follows −

False

Example 3

Now, we are checking '0' is a finite number using cmath.isfinite function.

import cmath
result = cmath.isfinite(0)
print("The result is:", result)

Output

We will get the following output −

The result is: True

Example 4

In the below example if the given value is not a number then this cmath.isfinite function returns TypeError.

import cmath
res = cmath.isfinite("Welcome to Tutorialspoint")
print(res)

Output

The result is produced as shown below −

Traceback (most recent call last):
  File "/home/cg/root/27484/main.py", line 2, in 
    res = cmath.isfinite("Welcome to Tutorialspoint")
TypeError: must be real number, not str

Example 5

In this example, we are checking if NaN(Not a Number) is a finite floating-point using cmath.isfinite() function.

import cmath
res = cmath.isfinite(float('NaN'))
print(res)

Output

We will get the output as shown below −

False
python_modules.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy