isFloat: Without Exception-Handling

Gerhard Häring gerhard.haering at
Wed Sep 18 14:13:01 EDT 2002

Rajarshi Guha wrote:
>>> def isFloat(string):
>>>   if type(string) == type(1.0):
>>>     return 1
>>>   else
>>>     return 0
>>> This should do what you want without exceptions
> If you call it as isFloat(1.2) it works

It answers no interesting question, however. Cos if I want to test if something
is a float or not i use type() or isinstance() anyway.

The original question was how to test if a /string/ can be converted to a

-- Gerhard

More information about the Python-list mailing list