How to get the type of an object?

smichr at gmail.com smichr at gmail.com
Wed Dec 21 12:24:24 EST 2005


You can use the type() function:

###
>>> s='hello'
>>> type(s)
<type 'str'>
>>> type(s)==str
True
>>> n=1
>>> type(n)
<type 'int'>
>>> type(n)==int
True
###

You can do the same with list, too. So you could write,

if type(x)==list:
    #do list action

/c




More information about the Python-list mailing list