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

Noah Hall enalicho at
Tue Jan 31 19:58:20 EST 2012

On Wed, Feb 1, 2012 at 12:44 AM, Andres Soto <soto_andres at> wrote:
> Hi,
> I'm writing a function which receive a list which elements are strings or
> new lists (sublists) containing strings.
> How can I verify if sone element of the list (which is contained in a
> variable) is a list or a string?
> I found the method isinstance(object,class) but I don't know which class
> should I use for.
> Thank you, regards
> Prof. Dr. Andrés Soto

"list" and "str"

>>> my_list = [1, 2, 3]
>>> isinstance(my_list, list)
>>> my_string = "foobar"
>>> isinstance(my_string, str)

More information about the Python-list mailing list