Python Lesson 2: Writing Your First Program and Practical Application of Variables

Python Lesson 2: Writing Your First Program and Practical Application of Variables

45 min
January 15, 2026
Step 1 of 4

Quick Review and Writing Your First 'Hello World' Program

Chapter 1: Quick Review and Writing Your First 'Hello World' Program

Welcome back, future Python developer! In our first lesson, we laid the groundwork by exploring what Python is, why it's a fantastic language to learn, and how to set up your development environment. Now, it's time to transition from theory to practice. This chapter serves as a crucial bridge. We'll start with a rapid-fire review of the core concepts from Lesson 1 to ensure you're on solid footing. Then, we will dive headfirst into the most sacred tradition in programming: writing your first "Hello, World!" program. This simple act is your first step in commanding the computer to do your bidding.

Part 1: Lightning-Fast Review of Python Fundamentals

Before we write new code, let's cement the key ideas from our introduction. Python is a high-level, interpreted, and general-purpose programming language. Let's break down what that means for you:

  • High-Level: You write code in a syntax that is (relatively) close to human language, not in complex machine code. Python handles the complex low-level operations for you.
  • Interpreted: Python code is executed line-by-line by the Python interpreter. This allows for quick testing and debugging, as you don't need to compile the entire program before running it.
  • General-Purpose: You can use Python for virtually anything: web development (Django, Flask), data science (Pandas, NumPy), artificial intelligence (TensorFlow, PyTorch), automation, scripting, and more.

Your development environment should now consist of two main components: the Python Interpreter (installed from python.org) and a Code Editor or IDE (like VS Code, PyCharm, or even a simple text editor). You verify the installation by opening your system's terminal or command prompt and typing:

python --version
# or sometimes
python3 --version

This command should return something like Python 3.11.4. Seeing this output confirms the interpreter is correctly installed and accessible from your command line, which is essential for running your scripts.

Note: If you're on Windows and the python command isn't recognized, you may need to add Python to your system's PATH environment variable during installation or manually afterwards. Re-run the installer and ensure the "Add Python to PATH" checkbox is selected.

Part 2: The Anatomy of Your First Python Script

A Python program is essentially a text file containing a series of instructions. By convention, we save these files with a .py extension (e.g., hello_world.py). This extension tells your operating system and editor that the file contains Python code, enabling syntax highlighting and other helpful features.

Let's create this file. Open your chosen code editor, create a new file, and immediately save it as hello_world.py in a dedicated folder for your Python projects (e.g., C:\Users\YourName\PythonProjects or /home/yourname/python_projects). Organization from the start is a key professional habit.

Part 3: Writing and Deconstructing "Hello, World!"

In your new hello_world.py file, type the following single line of code:

print("Hello, World!")

This is a complete, valid Python program. Let's dissect it with the precision of a surgeon to understand every component:

  • print: This is a built-in function. A function is a reusable block of code designed to perform a specific task. print()'s task is to output data to the standard output device, which is typically your terminal or console window. The parentheses () are mandatory and indicate we are "calling" or executing this function.
  • "Hello, World!": This is a string. A string is a sequence of characters (letters, numbers, symbols) enclosed within quotation marks. You can use either single quotes ' ' or double quotes " " in Python. This string is an argument being passed to the print() function. The function takes this argument and displays it.
  • The Complete Statement: The line print("Hello, World!") is an executable statement. When the Python interpreter reads this line, it performs the action: calling the print function with the string argument.
Pro Tip: Functions can take multiple arguments, separated by commas. Try print("Hello,", "World!"). The print() function will output them with a space in between by default. This is your first glimpse into a function's flexibility.

Part 4: Executing Your Program

Writing the code is only half the battle. Now we must run it. There are two primary methods:

Method 1: Using the Terminal/Command Line (Recommended)

This is the most common and powerful way to run Python scripts.

  1. Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux).
  2. Navigate to the directory where you saved hello_world.py

Tutorial Video

Loading ratings...