How can I verify if the content of a variable is a list or a string?
soto_andres at yahoo.com
Wed Feb 1 02:11:05 CET 2012
okok, my mistake is that I was using string in place of str. Thank you!!
Prof. Dr. Andrés Soto
> From: Noah Hall <enalicho at gmail.com>
>To: Andres Soto <soto_andres at yahoo.com>
>Cc: "python-list at python.org" <python-list at python.org>
>Sent: Tuesday, January 31, 2012 6:58 PM
>Subject: Re: How can I verify if the content of a variable is a list or a string?
>On Wed, Feb 1, 2012 at 12:44 AM, Andres Soto <soto_andres at yahoo.com> wrote:
>> 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
>> DES DACI
>"list" and "str"
>>>> my_list = [1, 2, 3]
>>>> isinstance(my_list, list)
>>>> my_string = "foobar"
>>>> isinstance(my_string, str)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list