Your First Python Program: Hello, World!

Python 3.14 Β· βœ“ verified by execution on 2026-07-10

A program is a list of instructions that a computer follows one line at a time, top to bottom. You are about to write your first one β€” and run it right here in the page.

Your first line of Python

The instruction print() displays text in the output. Whatever you put between the quotation marks appears on screen. Press Run β€” then change the message and run it again.

python
print("Hello, World!")
Output
Hello, World!

That’s a complete Python program. One line is all it takes.

How Python reads your line

Three parts matter:

  1. print β€” the name of a built-in instruction (a function).
  2. The parentheses () β€” they hand your text to print.
  3. "Hello, World!" β€” text wrapped in quotation marks. Text in quotes is called a string literal: Python displays it exactly as written and never tries to interpret it.

You can hand print several strings at once, separated by commas β€” it joins them with spaces:

python
print("Python", "is", "fun")
Output
Python is fun

Single quotes work exactly like double quotes β€” pick one style and stay consistent:

python
print('Single quotes work too')
Output
Single quotes work too

An empty print() displays a blank line β€” useful for spacing output:

python
print("First line")
print()
print("Third line")
Output
First line

Third line

Your first errors (everyone gets them)

Errors are not failure β€” they are Python telling you exactly what to fix. Learn to read them from day one and you will debug faster than most learners. Two you will meet this week:

1. SyntaxError β€” Python can’t understand the line. Here the closing parenthesis is missing, so Python stops before running anything:

python
print("Hello, World!"
This example raises an error (on purpose)
SyntaxError

The message names the problem: the ( was never closed. Fix the typo, run again.

2. NameError β€” Python doesn’t know that name. Forget the quotes and Python thinks Hello is a variable you never created:

python
print(Hello)
This example raises an error (on purpose)
NameError

Read the last line of any error first β€” it names the error type and usually points at the exact spot.

Edge cases worth knowing

Check yourself

What does the print() function do?

Reveal answer

Displays text in the program's output β€” In Python, print() writes text to the program's output (usually your screen). It has nothing to do with paper printers.

What happens if you run print(Hello) β€” without quotation marks?

Reveal answer

Python raises a NameError, because it looks for a variable named Hello β€” Without quotes, Python treats Hello as a name to look up. No such name exists yet, so you get: NameError: name 'Hello' is not defined.

Which line makes Python display exactly 2 + 2 (and not 4)?

Reveal answer

print("2 + 2") β€” Quotation marks make something a string β€” literal text. print("2 + 2") displays the text as-is; without quotes, Python would calculate the math first.

Is Print("hi") the same as print("hi")?

Reveal answer

No β€” Python is case-sensitive, so Print raises a NameError β€” Python names are case-sensitive: print exists, Print does not. Capitalizing it raises NameError: name 'Print' is not defined.

Challenges

Challenge 1 +10 XP

Make Python display exactly this sentence: I am learning Python

python
  • Test 1 β€” expects "I am learning Python"
Need a hint? (βˆ’25% XP)

Put the whole sentence inside quotation marks, inside print().

Show solution (0 XP)
print("I am learning Python")

Challenge 2 +15 XP

Print a three-line introduction. Line 1: Hello! β€” Line 2: My name is Py. β€” Line 3: Nice to meet you.

python
  • Test 1 β€” expects "Hello!\nMy name is Py.\nNice to meet you."
Need a hint? (βˆ’25% XP)

Each print() starts a new line automatically.

Show solution (0 XP)
print("Hello!")
print("My name is Py.")
print("Nice to meet you.")