What is the command to determine an object's type?
Tino Lange
tl_news at nexgo.de
Wed Feb 6 14:31:44 EST 2002
On Tue, 05 Feb 2002 22:38:49 GMT, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:
Hi Fredrik!
(1) if type(l) == types.ListType:
>or better:
(2) if type(l) is types.ListType:
>or even better:
(3) if isinstance(l, types.ListType):
Why is "if isinstance(l, types.ListType):" even better than the rest?
What do you mean by "better"?
I just compared the speed of execution (using Python 2.1 on Linux) and
found consistently:
(2) is the fastest, the comes (3), (1) is much slower.
So I would guess (2) is the most effective implementation?
Tino
More information about the Python-list
mailing list