Python Basic Doubt

Chris Angelico rosuav at gmail.com
Sat Aug 10 17:37:22 EDT 2013


On Sat, Aug 10, 2013 at 7:00 PM, Xavi <jarabal at gmail.com> wrote:
> Now I have one doubt, I use 'is' to compare basic types in python 3, for
> example .-
>
> v = []
> if type(v) is list:
>     print('Is list...')
>
> Because I think it is more clear and faster than .-
> type(v) == [].__class__  ... or ... isinstance(v, list)
>
> Is this correct?
> Thanks.

This really should be a separate thread, rather than a follow-up to
the previous one, since it's quite unrelated. But anyway.

The isinstance check is the better one, because it will also accept a
subclass of list, which the others won't.

ChrisA



More information about the Python-list mailing list