+2 votes
in Programming Languages by (59.8k points)

Lets say x='1.34'. How can I check if the string x is a floating point number? 

The isnumeric() function does not work for float numbers.

1 Answer

+1 vote
by (353k points)
selected by
Best answer

Since there is a decimal point in the string, the isnumeric() function will return False. You can replace '.' with '0' to apply the isnumeric() function.

Here is an example:

>>> x='1.34'
>>> x.replace('.','0').isnumeric()