best way to find out type

Posted by laspal on Stack Overflow See other posts from Stack Overflow or by laspal
Published on 2010-04-23T19:29:48Z Indexed on 2010/04/23 19:33 UTC
Read the original article Hit count: 204

Filed under:

hi, I have a dict

val_dict - {'val1': 'abcd', 'val': '1234', 'val3': '1234.00', 'val4': '1abcd 2gfff'}

All the values to my keys are string.

So my question is how to find out type for my values in the dict.

I mean if i say`int(val_dict['val1']) will give me error.

Basically what I am trying to do is find out if the string is actual string or int or float.`

if int( val_dict['val1'):
dosomething
else if float(val_dict['val1']):
dosomething

thanks

© Stack Overflow or respective owner

Related posts about python