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

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Feb 2 02:31:16 EST 2012


On Wed, 01 Feb 2012 23:19:57 -0800, Rainer Grimm wrote:

> You can do it more concise.
> 
>>>> def isListOrString(p):
> ...    return any((isinstance(p,list),isinstance(p,str)))


Or even more concisely still:

isinstance(p, (list, str))



-- 
Steven



More information about the Python-list mailing list