In this article, you will see how to check a string is numeric in Python. A numeric string is a string that contains only numeric characters. You can use the isnumeric()
method to check if a string is numeric.
Step 1: Create a string
str = "1234567890" print("str = ", str) print("str type = ", type(str))
Step 2: Check if a string is numeric
if str.isnumeric(): print("Numeric") else: print("Not Numeric")
Output:
str = 1234567890
str type = <class 'str'>
Numeric
Free resources to learn advanced skills: AiHints and CodeAllow