How to determine a variable's datatype?

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Thu Mar 16 08:17:37 EST 2000


Peter Bittner wrote in comp.lang.python:
> Hi there!
> 
> Is it possible in Python to determine the datatype of an object?
> 
> E.g. (kind of like this)
>      var1 = 3
>      var2 = 'Hello'
>      var1.datatype   ==> yields "int"
>      var2.datatype   ==> yields "string" or list of characters


>>> x = 3
>>> type(x)
<type 'int'>
>>> type(x) == type(1)
1
>>> import types
>>> type(x) == types.IntType
1

Etc.
-- 
Remco Gerlich,  scarblac at pino.selwerd.nl
  3:16pm  up 10 days,  3:36,  6 users,  load average: 0.41, 0.43, 0.23



More information about the Python-list mailing list