Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python cmath.isfinite() Function



The Pythoncmath.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 Pythoncmath.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 usingcmath.isfinite() function.

import cmathx = 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 usingcmath.isfinite() function.

import cmathx = 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 usingcmath.isfinite function.

import cmathresult = 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 thiscmath.isfinite function returns TypeError.

import cmathres = 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 usingcmath.isfinite() function.

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

Output

We will get the output as shown below −

False
python_modules.htm
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp