How to find the type ...

Scott David Daniels scott.daniels at acm.org
Fri Dec 9 17:24:06 EST 2005


Xavier Morel wrote:
 > 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
Or even say "look to the text for a clue about the base":

     >>> int('0xe', 0)
     14
     >>> int('010', 0)
     8
     >>> int('10', 0)
     10

-- 
-Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list