In a programming language, the next line is represented by a newline character or a
\n character. This character indicates that whatever text is present after it will be printed in the next line. Strings are filled with these newline characters to represent the next lines.
In Python, we can use this character to print text in the next lines or create line breaks.
Newline Character or `
` in Python
Refer to the following code. It shows how one can use the newline character to create line breaks and print text in new lines.
print("Hello\nWorld") # Notice the use of \n print("My\nName\nIs\nPython") # Notice the use of \n a = [1, 2, 3, 4, 5] for x in a: print(x, end = "\n") # \n is append to the end of the string
Hello World My Name Is Python 1 2 3 4 5