What is the command to determine an object's type?

Mark McEahern marklists at mceahern.com
Tue Feb 5 15:43:09 EST 2002


MDK wrote:
> How can I tell if an object is a string, a list, or a dictionary in a
> program using if and ifelse so that I can perform a differnent action
> depending on the object's type?

$ python
>>> import types
>>> l = []
>>> if type(l) == types.ListType:
...     print "yeah baby!"
...
yeah baby!
>>>

// mark




More information about the Python-list mailing list