How can I verify if the content of a variable is a list or a string?
Rainer Grimm
r.grimm at science-computing.de
Thu Feb 2 02:19:57 EST 2012
More information about the Python-list mailing list
Thu Feb 2 02:19:57 EST 2012
- Previous message (by thread): How can I verify if the content of a variable is a list or a string?
- Next message (by thread): How can I verify if the content of a variable is a list or a string?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): How can I verify if the content of a variable is a list or a string?
- Next message (by thread): How can I verify if the content of a variable is a list or a string?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list