Print multiple lines in one statement without leading spaces

后端 未结 6 1442
有刺的猬
有刺的猬 2021-01-13 03:00

So for my first project it is a simple program that prints your name class you are in and what high school you went to. The one thing that is messing me up is for one of the

6条回答
  •  一生所求
    2021-01-13 03:49

    print inserts a space between each argument. You can disable this by adding , sep='' after the last '\n', but then there won't be any spaces between first_name and last_name or between course_id and course_name, etc. You could then go on to insert , ' ' manually where you need it in the print statement, but by that point it might be simpler to just give print a single argument formed by concatenating the strings together with explicit spaces:

    print(first_name + ' ' + last_name + '\n' + course_id + ' ' + course_name
          + ' ' email + '\n' + school + '\n')
    

提交回复
热议问题