Seeing with print, explaining with comments
How print writes several things at once, how sep and end change that, and why comments exist — your first tool for seeing inside a running program.
- 1Encounter
- 2Understand
- 3Worked
- 4Predict
- 5Apply
- 6Stretch
The problem we are solving
You wrote a program. You ran it. The terminal said nothing.
Did it work? Did it stop halfway? What did the calculation come to inside? There is no way to know, because a computer volunteers nothing — whatever you want to see, you have to ask for.
print is how you ask. Early on it is your only window: where the program got to, what a variable holds, what the arithmetic produced. Experienced developers drop print calls into code many times a day even with a debugger at hand — that is not a beginner's crutch, that is the job.
By the end of this mission you can
- Print several things in one call, and control the gap between them
- Reshape output with
sepandend - Spot the difference between text and numbers — why
"2" + "3"is not2 + 3 - Write comments, and tell which comments are actually worth writing
Prerequisites: The terminal, folders, and your first project.
print takes more than one thing
Separate as many values as you like with commas, and print writes them all on one line:
print("Order", 7, "confirmed")Order 7 confirmedNotice you never typed a space, yet the words came out spaced. print puts a single space between each comma-separated value on its own.
And at the end of every print, it moves to a new line:
print("line one")
print("line two")line one
line twoAn empty print() produces just a blank line — the simplest way to break long output into readable groups.
sep — the gap, your way
If that space is not what you want, change it:
print("2026", "09", "10", sep="-")
print("home", "user", "notes.txt", sep="/")
print("a", "b", "c", sep="")2026-09-10
home/user/notes.txt
abcend — what happens at the end of the line
By default print ends the line and moves down. That is adjustable too:
print("Loading", end="")
print(".", end="")
print(".", end="")
print(". done")Loading... doneFour separate print calls, one line of output — because the first three were told to put nothing at the end of the line.
Text and numbers are not the same thing
These two lines look nearly identical, and behave differently:
print(2 + 3)
print("2" + "3")5
23Inside quotes it is text, and + does not add — it joins. Outside quotes it is a number, and + really does add.
This distinction is the foundation of the missions that follow, and it is also the cause of about half the errors beginners hit. For now just hold onto the rule: quotes mean text.
Comments — the lines Python never reads
From a # to the end of that line, Python ignores everything:
# Friday delivery report
total = 12 + 8
print("Total:", total) # the sum shown at the bottom of the reportTotal: 20Comments have no effect on how the program runs. They are for people — for your colleague, and for you in three months, by which time you will have forgotten all of this.
*A good comment says why, not what.* What the code does is visible in the code:
# Weak: repeats what the code already says
count = count + 1 # add 1 to count
# Useful: gives the reason, which the code cannot show
count = count + 1 # the header row was counted too, so shift by oneYou learn nothing from the first one — the line plainly adds one. The second says why one is added, which no amount of reading the code would tell you.
While learning, comments have one more use — switching a line off temporarily to see how the program behaves without it:
print("first")
# print("second")
print("third")first
thirdA complete example
Create report.py and run it:
# A small sales report
print("=" * 24)
print("SALES REPORT")
print("=" * 24)
print("Items sold:", 3 + 5 + 2)
print("Revenue:", 3 * 120 + 5 * 90 + 2 * 250)
print()
print("Prepared by", "Rafi", sep=": ")========================
SALES REPORT
========================
Items sold: 10
Revenue: 1310
Prepared by: RafiLook at "=" * 24. Multiplying text by a number makes Python repeat it that many times, so there is no need to type twenty-four equals signs by hand to draw a rule.
When it breaks
SyntaxError: unterminated string literal A quote was opened and never closed. print("Hello) does this. Count the opening and closing quotes.
You need a quote inside the text Use one kind outside and the other inside: print("It's working") or print('She said "yes"').
print "Hello" raises SyntaxError That is Python 2 syntax. In Python 3 print is a function, so it needs parentheses: print("Hello"). The mistake usually arrives by way of an old tutorial or answer.
Giving sep or end a value without quotes print("a", "b", sep=-) will not run. sep and end always take text: sep="-".
Which language should comments be in? Python accepts Bengali comments, but in this course all code — comments, variable names, filenames — is written in English. The reason is practical, not stylistic: not everyone on the team your code lands in will read Bengali, and the error messages, the documentation and the answers you will search for are all in English. Explanation in Bengali, code in English — that split holds across every mission.
Step 4 of 6 — Predict
Check your understanding
What exactly appears in the terminal when these three lines run?
print("a", "b", "c", sep="-")
print("x", end=" ")
print("y")- Aa-b-c x y
- Ba-b-c x y
- Cabc x y
- Da-b-c x y
Both lines use +. What is the output?
print(2 + 3)
print("2" + "3")- A5 23
- B5 5
- C23 23
- D5, then an error — `+` cannot be used with text
What does this program print, and why?
price = 250
# price = 400
print("Price:", price)- A`Price: 250` — the second line is a comment, so Python never reads it
- B`Price: 400` — the later value wins
- C`Price: 250` then `Price: 400` — both lines run
- DAn error — the same variable cannot be assigned twice
Answering needs an account
Sign in to check your answers
The questions are above, and working them out in your head is the part that matters. Sign in to see the answers, the explanations and the three-level hints.
Your turn
Write a file called profile.py that produces exactly this output:
------------------------
NAME : Rafi
ROLE : Python learner
------------------------
Age next year: 23Three conditions:
- The top and bottom rules must be produced by multiplication, not by typing twenty-four dashes
- The
NAME : RafiandROLE : Python learnerlines must usesep - In the
Age next yearline, do not type the number yourself — arrive at it by addition, e.g.22 + 1
And put a comment on the first line of the file saying why the file exists — not what it does.
There is more in this mission
What you read above is the complete mission — nothing was cut out of it. Pro adds:
- What actually happens underneath — how Python runs this
- The full solution to the exercise, worked step by step
- Harder extra exercises
- The interview question on this topic, with a model answer
Step 6 of 6
Stretch — the chapter quiz
Ten questions from easy to hard. The last ones are difficult on purpose.
Sign in to take the quiz