[Tutor] makeing '1' into a '01' neatly ?

Michael Lange klappnase at freenet.de
Wed Apr 28 14:15:03 EDT 2004


On Wed, 28 Apr 2004 13:06:54 +0100
Dave S <pythontut at pusspaws.net> wrote:



> >>>>x = '1'
> >>>>x.zfill(2)
> >>>>        
> >>>>
> >'01'
> >  

> 
> zfill is cool, :-) Its not even in my learning python book !
> 
> Dave
> 
> _______________________________________________

I think it was new in Python2.1 or Python2.2 (at least in Python2.2.2 it works),
in older version you only have access to zfill() through the string module:

>>> import string
>>> x='2'
>>> string.zfill(x, 2)
'02'
>>> 

Michael



More information about the Tutor mailing list