Python check if string is number | Example code

Use Python String isnumeric() Method to check if the string is number or not. This method returns True if all the characters are numeric (0-9), otherwise False.

string.isnumeric() 

Python checks if the string is a number Example

Simple python example to Check if a given string is numeric or not.

str1 = "1234567890"

x = str1.isnumeric()

print(x)

Output:

Python check if string is number

This function is used to check if the argument contains all numeric characters such as integers (Number in Python), fractions, subscript, superscript, roman numerals, etc.(all written in Unicode)

Do comment if you have any doubts and suggestions on this Python condition check topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.