Python: Zero to Hero
Home/The Foundation
Share

Chapter 1: Your First Python Program

This chapter has one job: get Python running and write your first line of code. By the end, you will see output on your screen, understand what just happened, and be ready for everything that follows.

Let's go.

What is Python?

Python is a language for telling computers what to do.

You write instructions in a file. Python reads them, one line at a time, and carries them out. That's the whole idea.

Here is the world's most famous Python program:

print("Hello, World!")

Output:

Hello, World!

One line. One result. That's real Python code — the same language used by Google, Instagram, NASA, and Netflix.

Python is popular for a reason: it reads almost like plain English. Compare it to some other languages and you'll see why beginners love it. But don't let "beginner-friendly" fool you. The same language that teaches you to code is also used to build rockets and train AI models.

In plain English: Python is a set of instructions you write, and the computer follows them. Like a recipe, but for a machine.

How Python Runs Your Code

Before you write your first program, I want you to understand one simple idea: Python is an interpreter.

That means Python reads your code line by line and runs each line immediately, top to bottom.

print("Line 1")
print("Line 2")
print("Line 3")

Output:

Line 1
Line 2
Line 3

Python ran line 1, printed it, moved to line 2, printed it, then line 3. In order. Every time.

This is different from languages like C or Java, where you compile everything first into a separate program. With Python, you just run your file and it goes. That's why it's so fast to test ideas.

In plain English: Python reads your code the way you read a book — top to bottom, one line at a time.

Three Ways to Run Python

You have three options. Pick the one that feels right for you. You can always switch later.

Option A: Install Python on Your Computer

This is the most powerful option. Your code runs on your own machine, you can save files anywhere, and you're not dependent on the internet.

Step 1 — Download Python

Go to python.org in your browser. Click Downloads. The site will detect your operating system (Windows, Mac, or Linux) and suggest the right version. Download it.

Step 2 — Install Python

Run the installer you just downloaded.

  • Windows: Before you click "Install Now," check the box that says "Add Python to PATH." This is important. If you skip it, your computer won't know where to find Python. Then click "Install Now."
  • Mac: Run the .pkg file and follow the steps.
  • Linux: Python is often pre-installed. Open a terminal and type python3 --version to check.

Step 3 — Verify the installation

Open a terminal (Windows: search for "Command Prompt" or "PowerShell"; Mac/Linux: open "Terminal") and type:

python --version

You should see something like:

Python 3.12.4

The exact numbers will differ — anything 3.10 or higher is perfect for this book.

Your turn: Run the check above. Write down the version number you see. If you see an error instead, jump to the Appendix (page XX) for troubleshooting steps.

Option B: Run Python in Your Browser (Google Colab or Kaggle)

You don't need to install anything. Open a website, type code, run it. Done.

This is the fastest way to start, and it's completely free.

Google Colab

  1. Go to colab.research.google.com.
  2. Sign in with a Google account (or create one — it's free).
  3. Click New notebook.
  4. Click inside the gray code cell, type print("Hello, World!"), and press Shift+Enter.

You'll see the output appear right below the cell:

Hello, World!

That's it. You just ran Python in a browser.

Kaggle

  1. Go to kaggle.com and create a free account.
  2. Click Code in the left menu, then New Notebook.
  3. In the code cell that appears, type print("Hello, World!") and click the Run button (or press Shift+Enter).

In plain English: Colab and Kaggle are like Python running inside a webpage. You type code, they run it, you see the result. No installation. No setup. Perfect for right now.

Your turn: If you chose this option, run print("Hello, World!") in a cell. See the output. You're done with setup — jump ahead to "Your First Program" below.

Option C: VS Code with Jupyter

VS Code is a free code editor used by millions of professional developers. The Jupyter extension lets you run Python in "cells" — small runnable chunks — right inside the editor. This gives you the best of both worlds: a real editor on your computer, with the cell-by-cell style of Colab.

You need Python installed first (Option A), then:

  1. Download VS Code from code.visualstudio.com and install it.
  2. Open VS Code. Click the Extensions icon on the left sidebar (or press Ctrl+Shift+X on Windows, Cmd+Shift+X on Mac).
  3. Search for "Jupyter" and install the one by Microsoft.
  4. Search for "Python" and install the one by Microsoft too.
  5. Go to File -> New File, save it as hello.ipynb (the .ipynb extension makes it a Jupyter notebook).
  6. VS Code will show you a notebook with a code cell. Type print("Hello, World!") in the cell and press Shift+Enter or click the play button.

Output appears right below the cell:

Hello, World!

Your turn: Run print("Hello, World!") in a notebook cell. If it works, you're set up and ready.

Your First Program

No matter which option you chose, let's write a real program together — one that does something slightly more interesting than printing a single line.

If you're using Colab, Kaggle, or VS Code with Jupyter, type this into a code cell. If you installed Python and prefer plain files, open a text editor (not Word — Notepad, VS Code, or any plain-text editor), type this, and save it as hello.py.

print("Hello, World!")
print("My name is Python.")
print("I will teach you everything.")

Run it. You should see:

Hello, World!
My name is Python.
I will teach you everything.

Three lines of code, three lines of output. Python ran each print statement top to bottom, exactly as you wrote it.

What print() does: It takes whatever you put inside the parentheses and displays it on the screen. The text you want to show must be wrapped in quotes — either single (') or double ("). Both work the same way.

print("Double quotes work.")
print('Single quotes work too.')

Output:

Double quotes work.
Single quotes work too.

Your turn: Change the messages to say something about yourself. Add a fourth print line. Run it and see your custom output.

Reading Error Messages Without Panic

Here's a truth no other book tells beginners early enough: you will see error messages. Every programmer does, every single day. An error message is not a sign you're doing it wrong — it's Python telling you exactly what it needs from you.

Let's make an error on purpose so you know what to expect.

Type this and run it:

print("Hello, World!"

You'll see something like:

  File "hello.py", line 1
    print("Hello, World!"
                         ^
SyntaxError: '(' was never closed

That looks scary the first time. Let's read it together.

  • File "hello.py", line 1 — The error is on line 1 of your file. Python tells you exactly where to look.
  • The little arrow ^ — It points to the spot where Python got confused.
  • SyntaxError: '(' was never closed — "Syntax" means the grammar of the code. Python is saying: "You opened a parenthesis but never closed it." The fix is to add the missing ).

Fixed code:

print("Hello, World!")

Here are the three most common errors you'll see as a beginner:

SyntaxError — You made a typo or forgot something (a closing quote, a parenthesis, a colon). Python couldn't even understand the code.

print("Hello)   # missing closing quote — SyntaxError

NameError — You used a word Python doesn't recognize, usually because you mistyped a function name or used a variable before creating it.

Print("Hello")  # capital P — NameError: name 'Print' is not defined

Python is case-sensitive. print and Print are completely different things.

IndentationError — Python uses spacing (indentation) to understand the structure of your code. If the spacing is wrong, Python complains. You'll understand this more in later chapters when we start writing if statements and loops.

The habit to build now: When you see an error, read the last line first. It tells you the type of error and a short description. Then look at the line number. Go to that line and look for the issue. Nine times out of ten, the fix takes five seconds once you know where to look.

In plain English: An error message is Python's way of saying "I got confused here, and here's why." It's helpful, not hostile.

How to Use This Book

Before we move on, a quick word on how to get the most out of every chapter.

Read with your hands. Don't just read the code — type it. Typing code yourself is how it sticks. Copy-pasting is fine sometimes, but typing forces you to read every character.

Do every "Your turn" exercise. These are not optional. They're short, they're focused, and they're where the real learning happens.

Don't skip chapters. Each chapter builds on the one before it. Chapter 3 assumes you know Chapter 2. The structure is deliberate.

Break things on purpose. Once you get an example working, change something and see what happens. Delete a quote. Change a word. This is the fastest way to understand what each part of the code actually does.

Google is not cheating. Every professional developer searches for answers constantly. The skill is knowing what to search for and how to read what comes back. You'll build that skill naturally as you go.

What You Learned in This Chapter

  • Python is an interpreter that reads and runs your code line by line, top to bottom.
  • You can run Python three ways: installed locally, in a browser (Colab/Kaggle), or in VS Code with Jupyter.
  • print() displays text on the screen.
  • Text in print() must be wrapped in quotes — single or double, both work.
  • Error messages tell you what went wrong and where. Read the last line first, then find the line number.
  • Python is case-sensitive: print and Print are not the same.

What's Next?

You've got Python running and you've written your first program. Now it's time to make programs do more than just print fixed messages.

In Chapter 2, you'll learn about variables — a way to store information so your program can remember and use it. Instead of printing "Hello, World!" forever, you'll store your name in a variable and print that. A small step that opens up everything else.

Your turn: Before you go, try this. Write a program that prints three things: your name, your city, and one thing you want to learn this year. Save it, run it, and see your output. That's your first real program.

© 2026 Abhilash Sahoo. Python: Zero to Hero.