Hello, World!
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.
Run your first Python statements and recognize how Python displays output.
Example check: Worked and guided code samples are checked against CPython 3.13. Practice uses Pyodide 0.29.5 (Python 3.13) in your browser. How we check lessons
Video lesson: Hello, World!
The preview is stored on this site. YouTube loads only when you press Play. Watch on YouTube
Jump to a chapter
Read the video transcript
Select a timestamp to watch that moment on YouTube.
- 00:00
Welcome to your first coding lesson at PythonLessonLab. By the end of this video you will know the difference between a line of Python and the output it creates, how print displays text and calculations, and how to use a small error to understand what Python expected. Open the Hello, World lesson page. The editor contains three lines. The output area begins empty because we have not run those instructions yet. You can follow in your browser without installing Python. Before pressing Run, read the first two lines and predict the output. Do you expect to see quotation marks around the greeting? Do you expect the second line to show two plus three, or the number five?
- 00:44
Making a prediction gives you something concrete to compare with the result. Press Run. The greeting appears on one line and five appears on the next. Nothing appears for the third line. That one small run already reveals three rules we can test, change, and reuse in every later lesson. You can pause the video at any code frame, type the same lines into the lesson editor, and press Run. If your result differs from the video, compare the source one character at a time. A missing quote, an extra space inside a string, or a changed number may explain the difference. Reproducing an example exactly before changing it makes debugging much easier.
- 01:27
Start with the first print call. The parentheses contain the value we want to display. Here that value is a string, meaning text enclosed in quotes. Python removes the source-code quotes when it shows the value, so the output is the greeting itself. The second call contains the expression two plus three without quotes. Python evaluates that arithmetic first, then gives the result, five, to print. The program follows these statements from top to bottom, so the greeting appears before the number. The line beginning with a hash sign is a comment. It explains something to a person reading the source but adds no output. You can change the greeting to your own name and run again without changing the calculation.
- 02:12
Now open the deeper example on the page that prints Answer followed by six times seven. One version puts the multiplication expression outside the quotes, so Python evaluates it and displays forty-two. The other puts the symbols inside a quoted string, so it displays the characters six, asterisk, seven. That distinction is why moving a quote can change the meaning of an otherwise similar line. There is another useful behavior in this example: when print receives two values separated by a comma, it places a space between them by default. The next guide example shows how to control that spacing. It prints red, green, and blue with a vertical bar as a separator.
- 02:56
Then it prints Loading with three dots in place of the usual line break, so the following print places done on the same line. The separator and ending only affect presentation, not the underlying values. Finally, look at the example with quotation marks inside a string and a backslash followed by the letter n. An escaped quote lets the quotation mark appear as part of the message. The newline escape makes one string display across two visible lines. There are still only two print calls, but their output occupies three lines. If you get a surprising number of lines, check the string's contents and the end argument before adding more print calls.
- 03:36
Let us make a deliberate mistake. Remove the quotes around an ordinary word in the greeting and run it. Python now treats that word as a variable name, something whose value should have been defined earlier. No such name exists in this program, so it raises NameError. The message points to what Python searched for, which makes it more useful than a vague failure light. Restore the quotes when you mean literal text. Another mistake is writing print followed by a space and a string, without parentheses. In Python 3, print is a function and its argument must go between parentheses. That version produces SyntaxError.
- 04:17
Read the error, put the parentheses back, and rerun. When a line fails, isolate one small change at a time. If you alter the quotes, parentheses, and arithmetic together, it becomes harder to know which edit fixed the problem. Now complete the practical task yourself. Replace the generic greeting with a greeting that includes a person's name, ideally yours. Add a new print call for seven plus five. Do not put that calculation inside quotes, because the task asks for its numeric result. Predict the second output line before running: it should be twelve. If your output shows the text seven plus five instead, examine the quotes.
- 04:58
If it shows an error, read the error name and return to the matching line in the editor. Run the code until your output includes a personal greeting and the number twelve. Then use the task checker on the page and answer the three quiz questions. One asks what print displays for a quoted string, another asks which character begins a comment, and the third asks you to calculate the output of a print call. Try answering each question from the rule you observed in the console, not from a guess. You can always run another tiny experiment before choosing. This is how to use the site throughout the course: predict, run, inspect, change, and explain.
- 05:39
In the next lesson, we will give useful values names so a program can remember and update them instead of repeating literal text everywhere.
Understand the concept
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.
A closer look
Follow the reasoning, inspect each result, then try the suggested changes in the console below.
Source code is different from what appears on screen
The text you type is source code: instructions for Python to evaluate. The output is the result you see after those instructions run. A quoted string inside print is displayed as text. An arithmetic expression inside print is evaluated first, so the symbols you typed may disappear and be replaced by their numeric result.
That distinction helps you debug: compare what you intended to print with what Python actually received. In the example, one line calculates an answer while the other treats the calculation as ordinary text. Before running it, predict which line contains 42. Then change the quoted text to a different expression and observe that it still remains text.
print("Answer:", 6 * 7)
print("Answer: 6 * 7")Answer: 42
Answer: 6 * 7- Python evaluates 6 * 7 before the first call prints it.
- The second call has only one quoted string, so multiplication never runs.
- A comma makes print place a space between separate values.
Control the spaces and line breaks
A default print call adds a space between multiple values and ends with a newline. Those defaults are helpful for quick checks, but a label or compact report sometimes needs different punctuation. The sep argument changes what goes between values, while end changes what is placed after that particular call.
These arguments affect display only; they do not change the values being printed. Follow the calls in order and notice that the last two share one output line. Try replacing the separator with a comma, then ask yourself whether the final printed values or only their presentation changed. This is useful when making readable console reports.
print("red", "green", "blue", sep=" | ")
print("Loading", end="...")
print("done")red | green | blue
Loading...done- sep inserts the same string between the three color values.
- end replaces the first call's usual newline with three dots.
- The next print starts immediately after those dots.
Put special characters inside a string
Quotation marks delimit a string in source code, but sometimes the message itself needs quotation marks. Escape an inner double quote with a backslash when the outer string also uses double quotes. A backslash followed by n is a newline character inside the value, not two visible characters in the output.
This is a small example of the difference between how a value is written and how it appears. Read the source carefully and predict how many output lines it creates. If a program's output looks oddly split, check whether a newline escape was included in the string. You can also use single quotes around a string containing double quotes.
print("She said, \"Start!\"")
print("first\nsecond")She said, "Start!"
first
second- \" represents a quote character within a double-quoted string.
- \n becomes a line break when the string is printed.
- Two print calls can therefore produce three visible lines.
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.