0
\n isnt creating a new line. For example the output would be a Hello \n World instead of Hello World
\n issue
3 Antworten
+ 6
If your purpose is to write:
Hello
World
... with a blank line in between, you have to put twice '\n':
print("Hello\n\nWorld")
... as the first create a new line in meaning that cursor move down one line and most left, so it's ready to write on the next line. By outputing a second new line char, you move down the cursor one line more, leaving a blank line between previous writting and cursor...
But you don't need them by this way:
print("Hello")
print()
print("World")
... because at end of each string printed is added implicitly a new line character ^^
You can change this behaviour, by passing a second named parameter to the function:
print("Hello",end='')
print("World",end=":)")
... will output:
HelloWorld:)
... and the next print() will occurs next on same line ;)
+ 3
print("Hello\nWorld")
this outputs:
Hello
World
+ 2
Try...
print('Hello' '\n' 'World')
or...
print('Hello\nWorld')