Your first program
The print() function is how a Python program talks to you. Whatever you put between its brackets is shown as output.
print() in action
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.
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:
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.
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).
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.