isnumeric() String Method in Python with Examples

isnumeric() method returns True if the string is a numeric string otherwise it returns False.

A string is numeric if all characters in the string are numeric and there is at least one character in the string.

Example 1: isnumeric() String Method


message = '12345'

if message.isnumeric():
    print('"%s" is numeric string.' %(message))
else:
    print('"%s" is not numeric string.' %(message))

Output

"12345" is numeric string.

Example 2: isnumeric() String Method


message = '12345 a'

if message.isnumeric():
    print('"%s" is numeric string.' %(message))
else:
    print('"%s" is not numeric string.' %(message))

Output

"12345 a" is not numeric string.


Related String Methods