Lad wrote: > Hello > How can I find out in Python whether the operand is integer or a > character and change from char to int ? > Regards, > L. > You may want to try the "type" command. And there is no character type in cPython (unless you're using ctypes that is)
There is not much point though, you can use the "int" construct on your expression, Python'll try to convert the expression to an integer by itself (and throw an exception if it can't) >>> a = 3 >>> int(a) 3 >>> a = "3" >>> int(a) 3 >>> a = "e" >>> int(a) Traceback (most recent call last): File "<pyshell#5>", line 1, in -toplevel- int(a) ValueError: invalid literal for int(): e >>> You can even do base conversions with it: >>> a="0xe" >>> int(a) Traceback (most recent call last): File "<pyshell#7>", line 1, in -toplevel- int(a) ValueError: invalid literal for int(): 0xe >>> int(a,16) # Silly me, 0xe is not a decimal 14 >>> -- http://mail.python.org/mailman/listinfo/python-list