IsString
Rick Wotnaz
desparn at wtf.com
Mon Dec 12 11:42:09 EST 2005
"Tuvas" <tuvas21 at gmail.com> wrote in
news:1134404765.862884.296050 at g49g2000cwa.googlegroups.com:
> 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!
>
If you really need to, you can test for type:
>>> for x in ['3',3,3.1,3j]:
... print type(x)
<type 'str'>
<type 'int'>
<type 'float'>
<type 'complex'>
>>> for x in ['3',3,3.1,3j]:
... if type(x) is str: print "it's a string"
... elif type(x) is int: print "it's an int"
... elif type(x) is float: print "it's a float"
... elif type(x) is complex: print "it's a complex number"
it's a string
it's an int
it's a float
it's a complex number
--
rzed
More information about the Python-list
mailing list