print format

MRAB python at mrabarnett.plus.com
Mon Dec 14 20:21:13 EST 2009


mattia wrote:
> Hi all, I wanto to print just the first 5 characters of a string, why 
> this doesn't work (py3.1)?
>>>> print("{0:5}".format("123456789"))
> 123456789
> I know I could use print("123456789"[:5]), yeah it's a stupid example, 
> but isn't format for string formatting?
> 
That's because it's the _minimum_ width.



More information about the Python-list mailing list