[Tutor] question re type()

Ricardo Aráoz ricaraoz at gmail.com
Sat Oct 27 13:34:58 CEST 2007


Dick Moores wrote:
> 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?
> 

Just take the quotes off :

if type(n) == int or type(n) == long :


HTH




More information about the Tutor mailing list