Scripting

Python isnumeric() Method

Python isnumeric() Method

Introduction

The isnumeric() method is built-in Python allows handling string. This method will return True if all the characters in the string are numbers, if the characters in the string are not numbers it will return False. It can check integers, fractions, subscripts,…

Now we’re gonna teach you to use the isnumeric() method in Python.

Example

Example 1:

str = "874534"

x = str.isnumeric()

print(x)

Output:

True

Example 2:

str = "-2"

x = str.isnumeric()

print(x)

Output:

False

Definition

The isnumeric() method will return True if all characters in the string are numeric.

“-2” or “3.5” will return False because the characters “-“, “.” are not numeric.

The syntax

string.isnumeric()

Parameter Values:

No parameter.

More examples

Example 1:

str1 = "-1"

print(str1.isnumeric())

str2 = "7347"

print(str2.isnumeric())

str3 = "83jj38"

print(str3.isnumeric())

Output:

False

True

False

Example 2: Combining input() function

print("Enter the string:")

x = input().isnumeric()

print(x)

Output:

Enter the string: 32324

True

Conclusion

We just taught you to use the isnumeric() method in Python.

Thank you for referring!

Similar Posts