+ 1

The use of newline.

Why do we use \n ? What is the difference between using a ‚Äúspace‚ÄĚ and ‚Äú\n‚ÄĚ?

29th May 2018, 5:53 AM
Akshay Chaudhary
2 Respostas
+ 6
We use \n if we want the text after that to be on the next line. Space simply separates text between your characters/words, without it, text won't be much readable. print('This line has some space in between and \n a few \n newline characters', 'Thislinehasnospaceinbetweenbut\nafew\nnewlinecharacters')
29th May 2018, 6:18 AM
Lord Krishna
Lord Krishna - avatar
+ 4
To add a newline in a string, use the character combination \n: >>> print("Languages:\nPython\nC\nJavaScript") Languages: Python C JavaScript To add a tab (whitespace) to your text, use the character combination \t as shown at (1): >>> print("Python") Python >>> print("\tPython") (1) Python
29th May 2018, 6:14 AM
Rahul George
Rahul George - avatar