IsString
Peter Decker
pydecker at gmail.com
Mon Dec 12 14:04:42 EST 2005
On 12 Dec 2005 08:26:06 -0800, Tuvas <tuvas21 at gmail.com> 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!
Use isinstance().
e.g.:
x = 7
isinstance(x, int)
-> True
isinstance(x, basestring)
-> False
x = "Hello"
isinstance(x, int)
-> False
isinstance(x, basestring)
-> True
I always use the basestring class for comparison, unless I need to
know whether or not the string is unicode.
--
# p.d.
More information about the Python-list
mailing list