How to know it is a list?

John Hunter jdhunter at nitace.bsd.uchicago.edu
Mon Sep 10 17:07:01 EDT 2001


>>>>> "Henry" == Henry  <ht_xu at hotrmail.com> writes:

    Henry> How do check if a variable is a list?

import types
x = (1,2,3)
y = [1,2,3]

isinstance(x,types.ListType)   #returns 0
isinstance(y,types.ListType)   #return 1


See the Python Library reference for more type names:
http://python.org/doc/current/lib/module-types.html#l2h-327



More information about the Python-list mailing list