isFloat: Without Exception-Handling

Rajarshi Guha rajarshi at presidency.com
Wed Sep 18 13:21:26 EDT 2002


On Wed, 18 Sep 2002 12:47:40 -0400, Steve Holden wrote:


>>
>>
>> def isFloat(string):
>>   if type(string) == type(1.0):
>>     return 1
>>   else
>>     return 0
>>
>> This should do what you want without exceptions
> 
> I doubt that VERY much. Please test your code before submitting, or
> ensure you note it wasn't tested ...

[snip]

>>>> isFloat("banana")
> 0
>>>> isFloat("1.2")
> 0

If you call it as isFloat(1.2) it works



More information about the Python-list mailing list