Output and expressions
An expression produces a value. An instruction can do something with that value. Learning the difference helps you understand why code can run successfully while the output area remains empty.
print(), separate output values and distinguish an expression from visible output.Expressions make values
The expression 8 + 4 evaluates to 12. In the interactive Python prompt you often see that value displayed automatically. In a normal .py script, merely evaluating 8 + 4 does not print anything.
Use print(8 + 4) to send the calculated value to the output area. This is why the CF playground may display “No printed output” even when your code ran without an error.
Separate arguments
print() accepts more than one value separated by commas. By default, Python places a space between values and ends with a newline. These defaults are adjustable using the sep and end keyword arguments.
The output is not the program itself: you can change what the user sees without changing how you calculate the value.
Comments document intent
A # symbol starts a comment outside a string. Python ignores the rest of that line. Comments explain why a step exists or clarify a surprising decision; they are not a replacement for readable code.
Try removing a print() call while leaving the calculation. Observe that no visible result appears.
Try it yourself.
Choose a starting example or write something completely different. You control the code; the Run button executes what is in the editor, not a hidden preset.
Only the second expression is printed.
Press Run Python to execute the editable code.
Make both expressions visible, each on its own line.
Need a hint?
Wrap the first expression in print(...).
On first Run, a pinned Python runtime downloads from jsDelivr. Code executes locally in your browser's Web Worker, not on our server. It cannot inspect your normal PC files or Windows hardware. Avoid entering secrets. Heavy/infinite loops are stopped by a time limit.
Check your understanding.
Try answering each question before opening its reference answer. Explain the idea aloud or change an example to test it for yourself.
Why might a line containing only 8 + 4 produce no output in a script?
View answer
In a normal
.pyscript, writing8 + 4computes the expression but does not display it.print(8 + 4)sends12to standard output. An interactive Python prompt may automatically echo expression results; a script does not.What does the sep keyword change?
View answer
sepsupplies the separator placed *between multiple arguments* passed toprint(). By default it is a space:print("A", "B", sep="-")printsA-B. It does not alter the values themselves.
Where this leads.
Output becomes more interesting once we can name and reuse values.