>>> r, g, b = (111, 121, 131)
>>> packed = int('%02x%02x%02x' % (r, g, b), 16)
This produces the following integer:
>>> packed
7305603
You can then unpack it either the long explicit way:
>>> packed % 256
255
>>> (packed / 256) % 256
131
>>> (packed / 256 / 256) % 256
121
>>> (packed / 256 / 256 / 256) % 256
111
..or in a more compact manner:
>>> b, g, r = [(packed >> (8*i)) & 255 for i in range(3)]
>>> r, g, b
Sample applies with any number of digits, e.g an RGBA colour:
>>> packed = int('%02x%02x%02x%02x' % (111, 121, 131, 141), 16)
>>> [(packed >> (8*i)) & 255 for i in range(4)]
[141, 131, 121, 111]