Lesson 2 of 12

Hello, World! 👋

🎯 Grades 6–8 ⏱ ~25 minutes 💚 Intermediate

What You'll Learn

  • Write and run your first Python program
  • Understand what print() does
  • Use comments in Python

Your First Line of Code

By tradition, the first program every coder writes just prints the words "Hello, World!" to the screen. Let us do that right now!

Python
print("Hello, World!")

Type that in your Python editor and press Enter (or click Run). You should see:

Output
Hello, World!
🎉
Congratulations!

You just wrote your first Python program! Every professional coder started exactly where you are right now.

The print() Function

print() is a built-in Python function that displays text on the screen. Whatever you put inside the parentheses (in quotes) gets printed. Try these:

Python
print("Hello, Oklahoma!")
print("I am learning to code!")
print("Python is awesome!")

Comments — Notes in Your Code

A comment starts with a # symbol. Python ignores everything after # on that line. Use comments to explain your code:

Python
# This is my first Python program
print("Hello, World!")  # This prints a greeting
💡
Always Comment

Professional programmers write comments so other people (and their future selves!) can understand the code.

📝Personalize It!

Modify the Hello World program to:

  1. Print your name
  2. Print your city
  3. Print your favorite animal
  4. Add a comment above each print() explaining what it does
Quick Check

What does the print() function do?

ASaves a file
BDisplays text on the screen
CCreates a variable

How do you start a comment in Python?

A//
B#
C--

What is printed by: print(42)?

AThe word forty-two
B42
CNothing