Lesson focus · 6 min read

Python Print Exercises for Beginners

print() looks simple, but it is the fastest way to inspect a program. These exercises cover the details beginners trip over: separators, line endings, quotes, and formatted values.

Exercise 1: control the separator

By default, print puts a space between values. Use sep to choose another separator. Predict the output before running the example. Then change the separator to a colon and a space.

print("Latte", 4.5, sep=": ")

Expected: Latte: 4.5

Exercise 2: control the line ending

end replaces the newline that print adds at the end. This is useful when you want several print calls on one line. Remember that the next print starts exactly where the previous one stopped.

print("Loading", end="...")
print("done")

Expected: Loading...done

Exercise 3: format money

An f-string can format a float without manually rounding it. The format spec .2f keeps two digits after the decimal point. Try it with 4.5 and with 12.345; notice that formatting is display, not a change to the original number.

price = 4.5
print(f"Total: ${price:.2f}")

Expected: Total: $4.50

Exercise 4: debug a receipt

This example prints two columns. The width spec <8 left-aligns the item name, and .2f formats the price. Change the width or the currency symbol and predict how the spacing changes. Printing a small table is a useful way to inspect data before writing it to a file.

items = [("Latte", 4.5), ("Tea", 3.0)]
for name, price in items:
    print(f"{name:<8} ${price:.2f}")

A simple aligned receipt

Exercise 5: use end deliberately

A loop that prints without a newline is useful for progress messages. The final print adds the newline after the loop. If the output runs together, check whether you put end on the wrong print call or forgot the final newline.

for step in ["read", "check", "run"]:
    print(step, end=" ")
print("done")

Expected: read check run done

Your practice checklist

Common questions

What is the difference between sep and end?

sep goes between multiple arguments in one print call. end goes after the final argument, replacing the default newline.

Why does print add a space between values?

A space is the default separator. Set sep to an empty string if you want the values joined with nothing between them.

Can I print a number and text together?

Yes. An f-string is usually clearest: print(f"Total: {total}").

Practice print and strings

Twelve questions on output, separators, quotes, and f-strings.

Open practice

Keep reading: