Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19670

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

References <1328057052.56088.YahooMailNeo@web30601.mail.mud.yahoo.com>
From Noah Hall <enalicho@gmail.com>
Date 2012-02-01 00:58 +0000
Subject Re: How can I verify if the content of a variable is a list or a string?
Newsgroups comp.lang.python
Message-ID <mailman.5272.1328057942.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Feb 1, 2012 at 12:44 AM, Andres Soto <soto_andres@yahoo.com> 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
> DES DACI
> UNACAR

"list" and "str"

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How can I verify if the content of a variable is a list or a string? Noah Hall <enalicho@gmail.com> - 2012-02-01 00:58 +0000

csiph-web