Create your own
Lesson illustration

Using `print()` to Display Text, Values, and Results

Hello again. In the previous lesson, you created a Python workspace in Replit and practiced the core workflow: edit main.py, run the program, and inspect the console. You also saw that Python executes saved statements from top to bottom.

Now we will make print() a deliberate tool rather than just a first example. By the end of this lesson, you will be able to display text, individual numeric values, and the evaluated results of calculations. You will also know why quotation marks and parentheses matter.


print() asks Python to show output

print() is a built-in Python function. A function is a named action that Python knows how to perform. In this case, the action is displaying information in the console.

Write and run this in main.py:

print("Hello, Python!")

The output is:

Hello, Python!

There are three parts to notice:

  • print is the function’s name.
  • Parentheses () show that you are calling, or using, the function.
  • "Hello, Python!" is the value you are asking Python to display.

The output does not include the quotation marks. They tell Python that the characters inside are text, but they are not part of the text itself.

A line such as:

print("Hello, Python!")

is a statement: a complete instruction for Python to carry out.

Printing text

Text values in programming are called strings. A string can contain letters, spaces, punctuation, digits, or even be empty. It must be enclosed in matching quotation marks.

print("A short message")
print("Python can display punctuation: ! ? , .")
print("123")

Output:

A short message
Python can display punctuation: ! ? , .
123

Python accepts either double quotation marks or single quotation marks:

print("Using double quotes")
print('Using single quotes')

Both lines display text. For now, choose one style—double quotation marks are common—and use it consistently.

One benefit of double quotes is that an apostrophe can appear inside the text naturally:

print("Today's program uses print().")

Every opening quote needs a matching closing quote of the same kind. This is invalid:

print("Python is fun')

Python cannot tell where that string ends, so it reports an error.


Values without quotation marks

print() can display numbers as well as text:

print(12)
print(3.75)
print(-8)

Output:

12
3.75
-8

The difference between these two lines is important:

print(12)
print("12")

They happen to display similarly:

12
12

But they are not the same kind of value:

  • 12 is a numeric value.
  • "12" is text made of the characters 1 and 2.

That difference becomes crucial when you calculate with values. Python can calculate with the first value, while the second is text. The next lessons will name these value categories precisely; for now, develop the habit of using quotation marks only when you mean text.


Expressions: asking Python to compute

An expression is code that Python can evaluate to produce a value. A number alone is a simple expression:

print(8)

A calculation is also an expression:

print(8 + 5)

When Python runs this statement, it first evaluates the expression inside the parentheses. It computes , which produces . Then print() displays that result:

13

This is the essential pattern:

print(expression)

Python evaluates what is inside the parentheses, then displays the resulting value.

Print statements and expressions | Intro to CS - Python | Khan Academy

Watch “Print statements and expressions” from Khan Academy. It makes the distinction between a calculation that Python performs and a value that Python actually displays especially clear.

Watch why output is blank to see why a calculation alone does not show its result in a saved program. Then watch printing expressions for the basic print() syntax, one-statement-per-line convention, and the order in which output appears.

Try this program:

print(7 + 4)
print(20 - 6)
print(3 * 5)
print(18 / 2)

The output is:

11
14
15
9.0

Do not worry yet about why the final result has .0; you will investigate numeric types shortly. The key point is that print() displayed the result of each expression, not the expression itself.

A saved program does not automatically show calculations

In an interactive Python console, entering an expression such as 7 + 4 often displays 11 immediately. But in a saved program such as main.py, a bare expression normally produces no visible output:

7 + 4
print(7 + 4)

Only the second line displays something:

11

Python still evaluates the first calculation, but the program never asks it to show the answer. Use print() whenever you want an intermediate calculation or final result to appear in the console.

This is useful both for communicating with a user and for checking that a program is behaving as you expect.


One print() statement, one output line

By default, each call to print() ends by moving to a new line. That is why this code:

print("First")
print("Second")
print("Third")

produces:

First
Second
Third

Python runs the statements in order, from top to bottom. Therefore, the console output follows the same order as your code.

You can use blank lines in code to make a program easier for humans to read:

print("Daily summary")

print(12 + 8)

print("End of summary")

The blank lines in the editor do not automatically create blank output lines. Only a print() call produces console output. To deliberately display a blank line, use empty quotation marks:

print("Before")
print("")
print("After")

Output:

Before

After

Printing several values together

A single print() can display more than one value. Separate the values inside its parentheses with commas:

print("Score:", 18)

Output:

Score: 18

Python places a space between items separated by commas. This is especially useful when you want explanatory text beside a calculation:

print("Total:", 18 + 22)
print("Average:", (18 + 22) / 2)

Output:

Total: 40
Average: 20.0

Notice the roles of each piece:

CodeWhat it means
"Total:"Text to label the result
18 + 22An expression Python calculates
,Separates values being passed to print()
() around the full callEnclose what print() should display

The parentheses around (18 + 22) are not necessary in this particular line, because print() can already receive the expression. They can be helpful, however, when a calculation is longer:

print("Remaining balance:", 100 - (25 + 30))

Python evaluates the expression, including the parentheses controlling the calculation, and displays:

Remaining balance: 45

Commas versus +

You may also see strings joined with +:

print("Good" + "morning")

Output:

Goodmorning

Python does not insert a space when it joins strings this way. You would need to include one yourself:

print("Good" + " morning")

For output that mixes labels and numbers, commas are clearer at this stage:

print("Items purchased:", 3)

Avoid this:

print("Items purchased: " + 3)

It causes an error because the text and number are different kinds of values. The comma version lets print() display both without requiring you to convert anything.


A small output report

Create a short “study report” in main.py. Enter this code exactly, run it, then change the values and wording to make it your own:

print("Study report")
print("")
print("Practice sessions:", 4)
print("Minutes per session:", 25)
print("Total minutes:", 4 * 25)
print("")
print("Keep going!")

Its output should be:

Study report

Practice sessions: 4
Minutes per session: 25
Total minutes: 100

Keep going!

This is already a small but real program: it presents readable text, numeric values, and a calculated result. At this point, you must edit each number wherever it appears. In the next lesson, variables will let you give values names so that updating a program becomes far easier.

When checking your output, compare it character by character with what you expected:

  • Is each label inside quotation marks?
  • Are numbers you want Python to calculate outside quotation marks?
  • Does every print have opening and closing parentheses?
  • Does every string have matching opening and closing quotation marks?
  • Did you place each print() statement on its own line?

Key takeaways

print() is Python’s basic way to display output in the console:

  • Use print("text") to display a string.
  • Use print(42) or print(3.5) to display numeric values.
  • Put an expression inside print() to display its evaluated result, such as print(7 * 6).
  • In a saved program, a calculation by itself does not normally display anything; print() makes the result visible.
  • Each print() call normally produces output on its own line.
  • Separate several values with commas, as in print("Total:", 18 + 22). Python inserts spaces between them.

Next, you will give values meaningful names with variables, then use print() to inspect those values as a program runs.

Can't find a good explanation? Sign up and we'll make it for you

Sign up