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😅

4th Oct 2018, 1:16 PM
partha
partha - avatar
3 Respostas
+ 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.')
5th Oct 2018, 10:58 PM
HonFu
HonFu - avatar
+ 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
4th Oct 2018, 1:20 PM
Faisal
Faisal - avatar
0
oh thanks HonFu so it is to be used inside the quotes
6th Oct 2018, 12:45 AM
partha
partha - avatar