[Tutor] Testing a variable for being a number, string or other object...

Clay Shirky clay at shirky.com
Tue Aug 12 11:05:19 EDT 2003


> My first question is how do I test if a variable is a number or a string?  I
> need to to do this for error checking on values passed into methods.

type(), as in 

  hex_num  = "DECAFBAD"
  long_num = long(hex_num, 16)

  print type(hex_num)
  print type(long_num)

returns 

<type 'str'>
<type 'long'>







More information about the Tutor mailing list