![]() When you print multiple statements in Python, by default they print across multiple lines. ![]() We can see that the escape character isn’t printed, but that the newline character is printed in full. # Welcome to datagy!\nLearn Python and Data Science! Let’s see what this looks like: # Escaping the Newline Character in Python By prefixing this to the newline character, the newline character will be escaped. We can see that by including the \n newline character, that when the string was printed the text was split across multiple lines.Īs a fun aside, you may be thinking, “what if I actually want to print '\n'?” Thankfully, this is very simple to do! The \ character acts as the escape character. String = "Welcome to datagy!\nLearn Python and Data Science!" Let’s take a look at an example of how you can use the Python newline character, \n, to print on multiple lines in Python: # Printing on Multiple Lines in Python In essence, this character indicates where a line ends – any further characters will be printed on a new line. ![]() ![]() Wherever this character is inserted into a string, a new line will be created when the string is printed out. In Python, the character to create a new line is the \n character.
0 Comments
Leave a Reply. |