Python String isnumeric() MethodPython Functions


The isnumeric() method checks if a string consists of only numbers. If yes, the string is considered to be numeric.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

# contain only numbers
str1 = '123'

# contain numbers and letter
str2 = 'abc123abc'

# contain numbers and space
str3 = '123 '

print (str1.isnumeric())
print (str2.isnumeric())
print (str3.isnumeric())

Output:

True
False
False

Syntax

str.isnumeric()

Parameters

The method doesn’t take any parameters.

Return Value

It returns True and False, depending on whether the string is numeric.

© 2021 Programtips.org, all rights reserved. Privacy Policy | Contact Us