python logo

isnumeric python


Python hosting: Host, run, and code Python in the cloud!

The Python function .isnumeric() (which is part of every string) returns True if string is numeric. If the string is not numeric, it will return False.
You can use this in combination with if-statements which then allow you to branch your code. This is often used for input validation.

Syntax

It does not take any parameters. The format of .isnumeric() is:

str.isnumeric()

Related Course:
Python Programming Bootcamp: Go from zero to hero

Example

The example below defines a string and then checks if the string is numeric. We do this twice, first with a string that is not numeric and then with a string that is numeric.

str = u"someone speak python here? sssss"
print( str.isnumeric() )

str = u"12345"
print( str.isnumeric() )

Result:

False
True
BackNext





Leave a Reply: