How can I verify if the content of a variable is a list or a string?

Rainer Grimm r.grimm at science-computing.de
Thu Feb 2 08:19:57 CET 2012


You can do it more concise.

>>> def isListOrString(p):
...    return any((isinstance(p,list),isinstance(p,str)))
...
>>> listOrString("string")
True
>>> listOrString([1,2,3])
True
>>> listOrString(2)
False
>>> listOrString(False)
False

Rainer



More information about the Python-list mailing list