On Thu, Feb 24, 2011 at 9:03 AM, 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.
>
>
>
>
>
>
>
>
>
> _______________________________________________ Tutor maillist -
> Tutor@python.org To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

As was explained by another poster earlier, the idea of leading zeros in the
internal representation of a number is meaningless.  If I have 05 of
something, or I have 5 of something  I have the same number of things.  So,
when the python shell prints out a number, it has no reason to print leading
zeros.  How would it know you want them?  If you do want leading zeros
because it makes your display look more proper, then you do the string
formatting to get what you need.

Go back and read some tutorials or the python manual to understand data
types.

-- 
Joel Goldstick
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to