CodeMIRAI
0 XP

Your first program

2 min read 5 runnable examples Quiz included

The print() function is how a Python program talks to you. Whatever you put between its brackets is shown as output.

Python
print("Hello!")
print("Welcome to CodeMIRAI.")
print(42)
print(3.5 * 2)

Each print() starts a new line. Notice that text goes inside quotes, but numbers and calculations do not.

Text is called a string

Text in quotes is called a string. You can use double quotes or single quotes; they work the same way.

Python
print("Double quotes work")
print('Single quotes work too')
print("It's easy to put an apostrophe inside double quotes")

If you forget the quotes, Python thinks you mean the name of something and gets confused:

Python
print(Hello)

That error, NameError: name 'Hello' is not defined, is one you will see often. It means "I don't know anything called Hello". Add the quotes and it works.

Printing several things at once

Give print() several values separated by commas and it prints them with a space between each one.

Python
print("I am", 21, "years old")
print("2 + 3 =", 2 + 3)

The values you pass to a function are called arguments. Here print() received three arguments: a string, a number and another string.

Changing the separator and the ending

print() has two optional settings: sep (what goes between values) and end (what goes at the end instead of a new line).

Python
print("2026", "10", "29", sep="-")
print("Loading", end="")
print("...", end="")
print(" done!")

Your turn

Write a program that prints three lines: your name, your favourite food, and the result of 7 * 6. Open the playground to try it, or edit any example on this page.

Finished this lesson?Mark it complete to earn +20 XP and move your progress on.