LambdaLabTM
Computer Science · Class 11 · Displaying Output
OutputFoundations⏱️ 8 min read

The print() Function

A program that does clever work but shows you nothing is not much use. print() is how Python shows things on the screen. In short, it displays all sorts of content for you: text (which programmers call a string), numbers, and other kinds of values you will meet as you go along. To start with, remember one rule — text goes inside single or double quotes, numbers do not.

1Why do we call it a function?

print() is also the easiest place to meet two words you will hear again and again: function and argument. Take them one at a time, starting with function.

Note
First, one word. The round brackets ( ) have a proper name in programming: parentheses. From now on, whenever this course says parentheses, it simply means these round brackets ( ). Same thing, proper name. Your textbook and your exam paper will use this word too, so it is worth getting used to.

So, why is print() called a function? Because of the parentheses. That is the simple answer, and for now it is enough:

Key Takeaway
A word with parentheses ( ) right after it — print(), input(), len(), type() — is a function. The ( ) is the clue.

This is a simple, everyday definition. The full definition needs ideas you have not learnt yet, so we will use this one for now. It is not wrong. It is just not the whole story. When you learn the rest later, this rule will still hold.

And it works for every function, not just print(). Any time you see a new word with parentheses after it, you already know what it is.

2The parts of one line

Here is the most famous line in programming. Tap each part of it. New words are easier to learn when you can point at what they mean.

Tap any part of the line
Four parts, four names. Tap one to see what it means.

So, to show something in Python, you put it inside the parentheses of print(). And the thing you put inside has a name. It is called an argument.

Note
About these new words. Function, argument, string — they come at you fast. Each one is just a name for something simple. Do not worry if they feel strange today. Use them a few times and in two weeks they will feel normal.

3Type your first line

Tip
Practise at the prompt. Open interactive mode on your computer — the steps are in the previous lesson — and type every example below yourself. In this lesson, a line starting with >>> is what you type. The line under it is Python's answer.

Type this at the prompt and press Enter. Python answers straight away:

Python prompt — interactive mode
>>> print('Hello, world!')
Hello, world!

Look at what did not appear: the quotes. You typed 'Hello, world!' and Python showed Hello, world!. The quotes only tell Python “this is text”. They are not part of the message, so they are not printed.

No Python on your computer yet? Then use the prompt below. It is a real Python prompt, running here in the page. Type a line, press Enter, and Python answers — exactly as it would in your own terminal.

Python prompt — interactive mode
# Type a print() line and press Enter.
>>>
try

4Printing more than one thing

You can give print() several arguments at once. Just separate them with commas. Python prints them in order and puts one space between them. You do not have to add that space yourself.

Python prompt — interactive mode
>>> print('Ramesh', 'Kumar', 17)
Ramesh Kumar 17

Notice the spaces between Ramesh, Kumar and 17. You did not type them. Python added them. Try it at the prompt below — add an argument of your own, and see what changes.

Python prompt — interactive mode
# Try several arguments. Separate them with commas.
>>>
try

An empty print() — with nothing inside — is not an error. You asked it to show nothing, so it shows nothing and moves to the next line. This is how you print a blank line.

Python prompt — interactive mode
>>> print('Line one')
Line one
>>> print()
 
>>> print('Line three')
Line three

5Every print() starts a new line

When print() finishes, it moves down to a new line. So two print() lines always give you two lines of output. This one is easier to see in script mode: the two lines of code run together, and the output arrives as a block, with no >>> prompts sitting in between.

📄 lines.py
print('First')
print('Second')
Output
First
Second
Tip
Want both on one line? Then use one print() with two arguments: print('First', 'Second'). The number of output lines is simply the number of times you called print().

6Recap

Key Takeaway
print() is a function — we know that because of the parentheses ( ). What you put inside them is called an argument, and that is what gets shown. Several arguments, separated by commas, print on one line with a space between them. No argument prints a blank line. And every print() ends by starting a new line.
Quick Check

How do we know that print is a function?

Quick Check

What does print('Sara', 'Ali') show?