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

Fredrik Lundh fredrik at pythonware.com
Tue Feb 5 17:38:49 EST 2002


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

or better:

    if type(l) is types.ListType:
        ...

or even better:

    if isinstance(l, types.ListType):
        ...

or, in 2.2 or later:

    if isinstance(l, list):
        ...

</F>





More information about the Python-list mailing list