How to write multiple strings in one line?

后端 未结 11 656
谎友^
谎友^ 2020-12-01 03:28

I\'ve started to learn Python with LPTHW and I\'ve gotten to exercise 16:

http://learnpythonthehardway.org/book/ex16.html

And feel like an idiot because I ca

11条回答
  •  心在旅途
    2020-12-01 04:01

    LPTHW: Exercise 16, Study Drill 3

    There's too much repetition in this file.

    Use strings, formats, and escapes to print out line1, line2, and line3 with just one target.write() command instead of six.

    more powerful implementation of target.write # Study Drill 3

    formatter = "{0}\n{1}\n{2}\n"
    target.write(formatter.format(line1,line2,line3))
    

提交回复
热议问题