xor on strings

Jason Orendorff jason at jorendorff.com
Mon Feb 11 00:44:19 EST 2002


dsavitsk wrote:
> >>> red = hex(56)[2:4]
> >>> green = hex(156)[2:4]
> >>> blue = hex(12)[2:4]
> >>> thestring = '&H' + blue + green + red
> 
> but here, since the blue string is only 1 character it throws the 
> rest off.

>>> colors = (56, 156, 12)
>>> print '&H%02x%02x%02x' % colors
&H389c0c

If you would prefer to have a function instead,
you can use string.zfill().

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list