Sarad Sa.
Sarad Sa.

Reputation: 79

How to add a line break in python?

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.

Upvotes: 4

Views: 65716

Answers (4)

user1220514
user1220514

Reputation: 21

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

Upvotes: 1

papey
papey

Reputation: 4134

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

Upvotes: 3

Simon Hobbs
Simon Hobbs

Reputation: 1010

You can print new line characters:

print('\n'*numlines)

Upvotes: 8

Johannes
Johannes

Reputation: 3388

\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

Upvotes: 6

Related Questions