String to int newbie question
reply.in at the.newsgroup
Sat Mar 22 14:44:55 CET 2003
>I want to convert a number string ( '3211' for example ) to a number,
>( actually integer ) preserving the original number
Is there any other way?
>( the exact number being string and integer )
>but if my number string starts with one or more zeroes,
>then the numbers won't be same...
Yes they will. '0027' and '027' both convert to 27.
>For example, if I have string = '0027' then int(string) would give 27.
>How can I add leading zeroes to that number?
By not converting it to an integer. It already had leading
zeroes before you converted it :-)
0027 == 027 == 27
More information about the Python-list