On Thu, Feb 24, 2011 at 3:03 PM, tee chwee liong <tc...@hotmail.com> wrote:
>>>> '0x' + hex(543)[2:].zfill(5)
> '0x0021f'
>
> this is a good way but it's still in string format. but if i convert it to
> long, then the leading 0s will be truncated. i guess can't have it both way.

A long is just a number. You cannot say that a number has or does not
have leading zeroes. Only _a representation of_ that number has. The
numbers 3, 1+2 and 0000000000003 are all the same number, so you
cannot say that the first does not have leading zeroes whereas the
last one has. To make the concept of 'leading zeroes' a meaningful
one, you _first_  have to re-convert the number to a string. Whether
or not there are leading zeroes depends on how that conversion is
done. If you use Python's standard conversion method, the result will
be a string representation without leading zeroes, but there are other
conversion methods that do give leading zeroes.

-- 
André Engels, andreeng...@gmail.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to