Simple string formatting question

Aahz Maruch aahz at
Tue Mar 14 16:56:38 CET 2000

In article <meh9-EBBAB3.10525814032000 at>,
Matthew Hirsch  <meh9 at> wrote:
>I'm trying to print this:
>print '%5.3f %5.3f %5.3f 1i'% 
>+ 1)
>but it won't fit on one line.  It keeps thinking that I have two 
>separate incomplete statements.  What is the correct way to get around 
>this problem?  Thanks for your help.

There are many ways; here's the simplest:

print '%5.3f %5.3f %5.3f 1i' % (temp_list[0], temp_list[1],
	temp_list[2], temp_list.index(min(temp_list))+1)

Python is smart enough to know that a comma means that the line can't
end.  We generally recommend that you indent the continuation line.

Side note: you've got four items in your tuple, but use only three in
your format string.
                      --- Aahz (Copyright 2000 by aahz at

Androgynous poly kinky vanilla queer het    <*>
Hugs and backrubs -- I break Rule 6

Three sins: BJ, B&J, B&J  --Aahz

More information about the Python-list mailing list