Checking the type

Fredrik Lundh fredrik at pythonware.com
Thu Mar 22 18:39:40 EST 2001


Ken Seehof wrote:
> The compare is a tiny bit slower, but looks nicer (I think).
>
> >>> a = [2,3,4]
> >>> b = "3,4,5"
> >>> def foo(x):
> ...  if type(x) == type([]):   # just use type() with a literal

for extra guru points, use "if type(x) is type([])" (there's only one
type object for each type), or better:

    if isinstance(x, type([])):
        ....

Cheers /F





More information about the Python-list mailing list