String to int newbie question

Dan Bishop danb_83 at yahoo.com
Sun Mar 23 00:10:45 CET 2003


Rene Pijlman <reply.in at the.newsgroup> wrote in message news:<a2qo7vkjkt1libm4c4scrt3qnug88khuhb at 4ax.com>...
> Boris Genz:
> >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 )
> 
> Que?
> 
> >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

No, 027 == 23.  But it is true that int('0027'), int('027'), and
int('27') are all equal.




More information about the Python-list mailing list