4

I just made a program in python but the statements are too close to each other in the output. So how can i add a line break between two statements in python.

2
  • Do you mean a line break in your script, or a line break in your output? Commented Jul 28, 2017 at 16:04
  • You can simply do a print or print() on its own to give you a blank line. Commented Jul 28, 2017 at 16:04

4 Answers 4

8

You can print new line characters:

print('\n'*numlines)
Sign up to request clarification or add additional context in comments.

Comments

6

\n gives you a new line. You can put it anywhere in a string and when printing it you get a new line.

In [1]: print('ab')
ab

In [2]: print('a\nb')
a
b

There are more of this kind, including tabs etc. https://docs.python.org/3/reference/lexical_analysis.html#literals

Comments

3
print(output1 + "\n")
print(output2)

Comments

1

To print a list of statements with line break:

    list=['statement one','statement two', 'statement three']
    list_element_on_separate_line = '\n'.join(list)
    print(list_element_on_separate_line)`
>>>
statement one
statement two
statement three

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.