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

Chris Angelico rosuav at gmail.com
Wed Feb 1 04:48:50 EST 2012


On Wed, Feb 1, 2012 at 12:11 PM, Andres Soto <soto_andres at yahoo.com> wrote:
>
> okok, my mistake is that I was using string in place of str. Thank you!!
> regards

Tip: In the interactive interpreter, enter:

>>> type("spam")
<class 'str'>

In Python 2, it'll say "type" not "class", but same diff. It tells you
there what the type is.

Same can be used for any other literal, name, or other object. Can be
quite handy at times.

ChrisA



More information about the Python-list mailing list