Hello, World!
Run your first Python statements and recognize how Python displays output.
Video coming to YouTube
Work through the full lesson and run its code while the video is being prepared for publication.
Understand the concept
A Python program runs its statements from top to bottom. The print function sends a value to the output area, so it is a quick way to check what your code does.
Text is a string and needs quotes. Numbers can be written without quotes. Lines beginning with a hash sign are comments for people reading the code.
- print() displays a value
- Strings use quotes
- Comments begin with #
See it step by step
Read the code, predict the output, then compare it with the result.
01. Print two messages
print("Hello, Maya!")
print("Welcome to Python.")Hello, Maya!
Welcome to Python.Python runs these statements from top to bottom. Quotes mark each piece of text.
02. Print a calculation
print(7 + 5)
# This comment is ignored.
print("Done")12
DonePython evaluates 7 + 5 before print() displays the result. The comment produces no output.
Try it in Python
Edit the example and run it. Python starts in your browser the first time you click Run.
Python console
Ready to runNeed input()? Add one value per line
Your output appears here.
Need a hint?
First change the text inside the greeting's quotes, keeping the print() call. Then add a new print(7 + 5) line; the number should appear as 12.
Complete the task and select Check task to verify your code.
Quick quiz
Three questions. You can change your answers and try again.
Typical mistakes
Everyone meets these errors. See what causes them and how to fix them.
Unquoted text
print(Hello)print("Hello")What happens: NameError: Python looks for a variable named Hello.
Put literal text inside quotes so Python treats it as a string.
Missing parentheses
print "Hello"print("Hello")What happens: SyntaxError in Python 3.
print is a function, so its argument goes inside parentheses.