Simple string formatting question

Aahz Maruch aahz at netcom.com
Tue Mar 14 10:56:38 EST 2000


In article <meh9-EBBAB3.10525814032000 at news.cit.cornell.edu>,
Matthew Hirsch  <meh9 at cornell.edu> wrote:
>
>I'm trying to print this:
>
>print '%5.3f %5.3f %5.3f 1i'% 
>(temp_list[0],temp_list[1],temp_list[2],temp_list.index(min(temp_list)) 
>+ 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 netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

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



More information about the Python-list mailing list