[Tutor] Convert string to long

Joel Goldstick joel.goldstick at gmail.com
Thu Feb 24 15:27:25 CET 2011


On Thu, Feb 24, 2011 at 9:03 AM, tee chwee liong <tcl76 at 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 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110224/ed6f1c49/attachment.html>


More information about the Tutor mailing list