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


Groups > comp.lang.python > #19772

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

Newsgroups comp.lang.python
Date 2012-02-01 23:19 -0800
References <1328057052.56088.YahooMailNeo@web30601.mail.mud.yahoo.com> <mailman.5271.1328057831.27778.python-list@python.org>
Subject Re: How can I verify if the content of a variable is a list or a string?
From Rainer Grimm <r.grimm@science-computing.de>
Message-ID <mailman.5346.1328167206.27778.python-list@python.org> (permalink)

Show all headers | View raw


You can do it more concise.

>>> def isListOrString(p):
...    return any((isinstance(p,list),isinstance(p,str)))
...
>>> listOrString("string")
True
>>> listOrString([1,2,3])
True
>>> listOrString(2)
False
>>> listOrString(False)
False

Rainer

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


Thread

Re: How can I verify if the content of a variable is a list or a string? Terry Reedy <tjreedy@udel.edu> - 2012-01-31 19:56 -0500
  Re: How can I verify if the content of a variable is a list or a string? Rainer Grimm <r.grimm@science-computing.de> - 2012-02-01 23:19 -0800
  Re: How can I verify if the content of a variable is a list or a string? Rainer Grimm <r.grimm@science-computing.de> - 2012-02-01 23:19 -0800
    Re: How can I verify if the content of a variable is a list or a string? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 07:31 +0000

csiph-web