CodeBlanks Logo Icon CodeBlanks

REPL and print

Learn the REPL and printing with print().

What is the REPL?

REPL stands for Read-Eval-Print Loop. It is the interactive environment that opens when you run the Python interpreter without a file.

In the REPL you type a line, press Enter, and Python runs it immediately and prints the result below. This is very handy for small experiments.

To start the REPL just type python3 in a terminal. To leave, use exit() or press Ctrl+D.

Printing output with print

To print something to the screen you use the print function. You put a value or a string inside the parentheses:

print("Hello world")

Strings are written inside double or single quotes. print automatically moves the cursor to a new line after printing.

You can print several values separated by commas: print("Result:", 42).

Practice Write your first program

Write a program that prints Hello world to the screen. Use the print function and a string in double quotes.

Starter code

main.py
# Print Hello world to the screen

Expected output

Hello world

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does this code do?

main.py
print("Hello")
  • Prints Hello to the screen Correct answer
  • Raises an error
  • Declares a Hello variable
  • Writes to a file

Explanation: print writes Hello to the screen.

2 Print hello world

Question
print(____)
Answer
print("Hello world")

Explanation: The string is in double quotes inside the print parentheses.

3 Which one is used to leave the REPL?

  • stop()
  • exit() Correct answer
  • kill
  • quit-now

Explanation: You leave with exit() or Ctrl+D.

All lessons in Beginner