[Tutor] question re type()

Dick Moores rdm at rcblue.com
Sat Oct 27 13:28:41 CEST 2007


I can't figure out how to test a variable n for its type.

An example that is the wrong syntax, but shows what I want to do:

if type(n) == 'int' or type(n) == 'long':
   do something

elif type(n) == 'float':
   do something else

elif type(n) == 'str':
   do something different

What's the correct way?

Thanks,

Dick Moores



More information about the Tutor mailing list