IsString

Larry Bates larry.bates at websafe.com
Mon Dec 12 15:18:03 EST 2005


Tuvas wrote:
> I need a function that will tell if a given variable is a character or
> a number. Is there a way to do this? Thanks!
> 
You can test the type of the object as follows:
>>> a='abc'
>>> isinstance(a, str)
True
>>> isinstance(a, (list, tuple))
False
>>>

The old way was to use type(a), but I think isinstance is
the new "preferred" method.

Larry Bates



More information about the Python-list mailing list