Introduction to Computer Science/Your First Program - "Hello World!"

Your First Program - "Hello World!"



🎯 Learning Goals for This Page
  • Write and execute your first complete line of Python code.
  • Understand the process of saving and running a Python file.
  • Identify the key components of a print() statement.

A Tradition is Born: "Hello, World!"

It's a long-standing tradition in computer science that the very first program you write in a new language simply prints the message "Hello, World!" to the screen. It's a simple task, but it proves that your entire setup is working correctly. Let's do it.


Step-by-Step Instructions

  1. Open Thonny (or your chosen online IDE).
  2. In the main editor window (the top part), type the following line of code exactly as you see it: python print("Hello, World!")
  3. Save your file. Go to File > Save As... and name it hello.py. The .py extension is very important as it tells the computer this is a Python file.
  4. Run the program. In Thonny, there is a large green "Run" button with a ▶ icon. Click it.
  5. Look at the "Shell" area at the bottom of the Thonny window. You should see the output: python Hello, World!
🎉 Congratulations! You are officially a Python programmer. 🎉

Code Breakdown

Let's quickly break down that one line of code:

  • print(): This is a built-in Python function. A function is a named block of code that performs a specific task. The task of the print function is to display whatever is inside its parentheses on the screen.
  • "Hello, World!": To work with text in Python, we use something called a string. A string is simply a piece of text, and we must enclose it in double quotes (") or single quotes ('). We put the string inside the parentheses to tell the print function what to display.

Interactive Sandbox

Use this space to practice writing code and complete the "Your Turn" activities above.

Python 3Initializing...
Loading code editor...
Program output will appear here...