Print and comments
You met print in the first lesson. It is the function you will use most while learning, because it is how a program shows you what it is doing. This lesson covers the useful extras of print and then comments, the notes you leave in a program for people.
Printing several things at once
Give print more than one value, with commas between them. It prints them on one line with a space between each.
print("Marks:", 87)
print("Asha", "Ravi", "Meena")
print("Total is", 40 + 47, "out of", 100)Output
Marks: 87
Asha Ravi Meena
Total is 87 out of 100You can mix text and numbers freely this way. Python adds the spaces for you.
Changing the separator
The space between values is called the separator. Change it with sep.
print("12", "11", "2026", sep="-")
print("a", "b", "c", sep="")
print("Name", "Class", "Marks", sep=" | ")Output
12-11-2026
abc
Name | Class | Markssep="" with nothing between the quotation marks means no gap at all.
Staying on the same line
After printing, Python moves to a new line. The end option changes what is added at the end.
print("Loading", end="")
print("...", end=" ")
print("done")Output
Loading... doneThe first two calls do not move to a new line, so all three pieces appear together. This is handy when a loop prints many small items in a row.
New lines and tabs inside text
Two special codes work inside any string. \n starts a new line. \t jumps to the next tab stop, which lines things up in rough columns.
print("Line one\nLine two")
print("Item\tPrice")
print("Tea\t10")
print("Samosa\t15")Output
Line one
Line two
Item Price
Tea 10
Samosa 15The backslash tells Python that the next letter is a code and not an ordinary letter. If you need a real backslash in your text, write two of them: \\.
Quotation marks inside text
Text can sit inside double or single quotation marks. Both mean the same. Use one kind outside when you need the other kind inside.
print("It's a sunny day")
print('She said "namaste" and smiled')Output
It's a sunny day
She said "namaste" and smiledAn empty print
Calling print() with nothing inside prints a blank line. Use it to give your output some air.
print("Report")
print()
print("End of report")Output
Report
End of reportComments
A comment starts with the hash sign #. Python ignores everything from the hash to the end of that line. Comments are for the human reader, which includes you three months from now.
# This program works out the area of a room
length = 12 # in feet
width = 10 # in feet
print("Area:", length * width, "square feet")Output
Area: 120 square feetGood comments say why, not what. # add 1 to x above the line x = x + 1 tells the reader nothing new. # the first row is a heading, so skip it is worth writing.
You can also switch a line off for a moment by putting a hash in front of it. Programmers call this commenting out. It is a quick way to test a program with and without one line.
print("This line runs")
# print("This line is switched off")Output
This line runsCommon mistakes
- Forgetting the comma between values:
print("Total" 50)is an error. - Writing
seporendbefore the values. They must come last. - Using a forward slash for a new line. It is
\nwith a backslash.
Try it yourself
Exercise 1. Print today's date as three numbers joined by slashes, using sep. Use the values 12, 11 and 2026.
Show one answer
print(12, 11, 2026, sep="/")Output
12/11/2026Exercise 2. Print a small menu of three items, each on its own line, using only one print.
Show one answer
print("1. Tea\n2. Coffee\n3. Lassi")Output
1. Tea
2. Coffee
3. LassiExercise 3. Print A B C using three separate print calls that all stay on the same line.
Show one answer
print("A", end=" ")
print("B", end=" ")
print("C")Output
A B CExamples on this page were run with Python 3.14 on 12 November 2026. The output shown is the real output.
This is an independent learning site. It is not connected with or approved by the Python Software Foundation. "Python" is a trademark of the Python Software Foundation and is used here only to name the language.