str(int_var) formatted

Grant Edwards invalid at invalid.invalid
Fri Oct 29 18:13:44 CEST 2010


On 2010-10-29, Tracubik <affdfsdfdsfsd at b.com> wrote:
> Hi all,
> i've to convert integer x to string, but if x < 10, the string have to be 
> '0x' instead of simple 'x'
>
> for example:
>
> x = 9
> str(x) --> '09'
>
> x = 32
> str(x) --> '32'
>
> x represent hour/minute/second.
>
> I can easily add '0' with a if then block, but is there a built-in way to 
> add the '0' automatically?

"%02d" % x

-- 
Grant Edwards               grant.b.edwards        Yow! INSIDE, I have the
                                  at               same personality disorder
                              gmail.com            as LUCY RICARDO!!



More information about the Python-list mailing list