REPL and print
- Python course
- Beginner
- Lesson 2/116
- 4 min
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
# Print Hello world to the screenExpected 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?
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
print(____)
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.