0
How to use \n ? Please give some examples.(in which situations this is used)
I searched through some sites but none was as good explanation here😅
3 Réponses
+ 1
You put a '\n' into a string to quickly and easily create a newline.
This happens automatically after a print-statement, as you probably know. But what if you want to insert an empty line?
You could do it like this:
print('First sentence.')
print()
print('Second sentence')
Or, to save time, you just write:
print('First sentence\n')
print('Second sentence')
Or you can even do this, making do with only one print-statement:
print('First sentence\n\n'
'Second sentence.')
+ 4
The \n character creates a newline in a string, making whatever text is after the character appearing on the next line rather than the same one.
For example, the string "Hello\nWorld" would output this:
Hello
World
0
oh thanks HonFu
so it is to be used inside the quotes