[Tutor] Newline

Alan Gauld alan.gauld at btinternet.com
Sat Dec 4 14:45:44 CET 2010


"Steven D'Aprano" <steve at pearwood.info> wrote

> >>> for i in (1, 2, 3):
> ...     print(i, "spam", end="\n" if i==3 else "***")

Ooooh! A new trick.
I hadn't thought of using the conditional expression there but it 
makes a lot of sense.
Definitely more fun and flexible than the old comma at the end of a 
print in v2 :-)

Thanks for that,

Alan G. 




More information about the Tutor mailing list