str(int_var) formatted

Tracubik affdfsdfdsfsd at b.com
Sat Oct 30 04:20:57 EDT 2010


Il Fri, 29 Oct 2010 19:18:41 -0700, John Yeung ha scritto:

> On Oct 29, 11:59 am, Tracubik <affdfsdfds... at b.com> wrote:
>> 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'
> 
> Everyone else seems to prefer the format-based solutions, which is fine.
>  I will give zfill a little exposure, as it seems unloved/ underused:
> 
> str(x).zfill(2)
> 
> John

I've also used zfill in my code, it make code more readable imo. Thanks to 
all for their kind help

Nico



More information about the Python-list mailing list