What is /n in Python?

iD Tech in action

In Python, \n is a type of escape character that will create a new line when used. There are a few other escape sequences, which are simply ways to change how certain characters work in print statements or strings. These include \t, which will tab in your text, and \", which will add a quotation in your print statement. 

Here is a visual summary:

Strings are variables that can hold data besides numbers, including words. When creating string variables, their value must be inside quotation marks, like this:  a_word = "between quotes" 

 doughnut_name = "Kepler" 
 print(doughnut_name) 

Going back to the points above, escape characters can be used to help format string output.

That said, you can make a multi-line string with three quotation marks. (You won't need \n characters with this option!)

my_multiple_line_string = """This is the first line 
This is the second line 
This is the third line""" 

A photo of Ryan

Ryan manages blog content at iD Tech, starting with the company in 2008. He earned his MBA from Santa Clara University after obtaining his Bachelor’s degree from Arizona State. Connect on LinkedIn!

Featured Posts

Categories

Authors

About iD Tech

iD Tech is the #1 tech camp on the planet, and world leader in youth STEM education, with programs held online and at 150+ global locations offering 50+ innovative tech courses: 

Coding camps
Video game camps
Robotics classes & camps
Creative arts classes & camps
All STEM camps

We've bet our reputation on recruiting the top instructors in the country. Our small classes ensure customized learning, leading to "a-ha moments" and awesome outcomes. Programs include:

On-Campus Programs

Online Tutoring

All Coding Courses