Lesson 1 of 16 · Level 1: Beginner

What Is Python? How to Install It and Write Your First Program

  • ⏱ 14 min read
  • ❓ 4 review questions
  • ✍️ Exercise with solution
In this lesson
  1. What you can do with Python
  2. How a program works
  3. Installing Python
  4. Your first program
  5. Interactive mode: Python as a calculator
  6. Comments: notes for humans
  7. Hands-on example: a hardware store receipt
  8. Indentation matters (a lot)
  9. Reading errors without fear
  10. Common beginner mistakes
  11. Checklist before lesson 2
  12. Summary
What you'll learn
  • What Python is and what people actually build with it.
  • How to install Python and VS Code on Windows, macOS or Linux.
  • How to write and run your first program.
  • How to read error messages calmly instead of panicking.
  • How to build your first useful script: a store receipt with sales tax.

Python is a programming language that reads almost like plain English, which makes it one of the best first languages you can learn. It's also a professional tool used by Google, Netflix, NASA and thousands of small businesses. In this first lesson you'll install it, write your first program and learn to read the error messages every programmer sees daily.

#1on the TIOBE index of programming language popularity (November 2026)
3.15is the latest stable version, released in October 2026
$0is what everything in this course costs: Python, VS Code and Google Colab are free
  1. See what Python is for
  2. Install Python and VS Code
  3. Run hello.py
  4. Learn to read errors
  5. Build a store receipt

What you can do with Python

Python is a "general-purpose" language: the same skills carry over to very different jobs.

Automate boring tasks

Rename hundreds of files, fill in spreadsheets, email reports, download data every morning.

Analyze data

With pandas and matplotlib you can crunch millions of rows that would freeze Excel.

Artificial intelligence

Most AI and machine learning tools are built with Python or used from it.

Web back ends

Django and FastAPI run the server side of websites: logins, databases and APIs.

Scripts and tools

Small programs for science, finance, engineering and everyday office work.

How a program works

A program is a list of instructions the computer carries out in order. Python is an interpreted language: a program called the interpreter reads your code line by line and runs it. There's no separate compile step, so you see results in seconds. Every program you write takes this trip:

  1. Step 1You write the codeIn VS Code, inside a file that ends in .py.
  2. Step 2You save the filePython runs what's saved on disk. If you forget to save, you run the old version.
  3. Step 3The interpreter reads itFirst it checks the syntax: quotes, parentheses and indentation.
  4. Step 4It runs line by lineTop to bottom: the order of the lines is the order things happen.
  5. Step 5You get output or an errorYou see what you printed or, if something breaks, an error message that points to the line.

Installing Python

Option 1: Nothing to install (start today)

Google Colab (free with a Google account) runs Python in your browser. It's enough until lesson 8, where you'll work with files.

Option 2: Install Python on your computer (recommended)

  1. Go to python.org → Downloads and get the latest stable release of Python 3.
  2. On Windows, python.org now points you to the Python install manager, the new official installer. Once it's installed, the py command manages your Python versions (for example, py install 3.15). If you use the classic installer instead, check "Add python.exe to PATH" on the first screen before clicking "Install Now." It's the step people forget most often.
  3. On macOS, run the downloaded .pkg installer.
  4. On Linux, Python is usually preinstalled; check it in the terminal.

To confirm the installation, open a terminal (on Windows, PowerShell or Command Prompt; on a Mac, the Terminal app) and type:

python --version

You should see something like Python 3.15.x (3.13 or 3.14 is fine too: this course works on Python 3.10 or newer). On macOS and Linux the command may be python3.

If the terminal doesn't recognize the command

The most common installation error on Windows looks like this:

'python' is not recognized as an internal or external command,
operable program or batch file.

Windows doesn't know where Python lives because it isn't on the PATH (the folders where Windows looks for programs). Reinstall with "Add python.exe to PATH" checked, or use the install manager, then close and reopen the terminal. Meanwhile, try py --version.

The code editor

Install Visual Studio Code (free) and Microsoft's official "Python" extension: you get syntax colors, autocomplete and a ▶ button that runs the current file.

Your first program

Create a file named hello.py with this content:

print("Hello, world!")
print("I'm learning Python")

Save it and run it with VS Code's ▶ button or from the terminal, inside the file's folder:

python hello.py

Output:

Hello, world!
I'm learning Python

print() is a function: a named instruction that does something. This one displays whatever you put inside the parentheses. Text goes inside quotes, double or single, as long as you open and close with the same kind (the second line uses double quotes because the text contains an apostrophe).

1. What does print("Hello", "world") display?

  • Helloworld
  • "Hello", "world"
  • Hello world

print() separates its arguments with a space and doesn't show the quotes. The quotes only tell Python where the text starts and ends.

Interactive mode: Python as a calculator

If you type just python in the terminal, you enter interactive mode (you'll see the >>> prompt). Each line runs as soon as you press Enter:

>>> 2 + 3
5
>>> 10 / 4
2.5
>>> 2 ** 10
1024
>>> 0.1 + 0.2
0.30000000000000004
>>> 4.35 * 100
434.99999999999994

Type exit() to leave. Surprised by the last two results? Computers store decimals in binary, and numbers like 0.1 or 4.35 have no exact binary version. Every language does this; it isn't a Python bug. You'll tidy the display with round() in the next lesson.

Comments: notes for humans

Everything after a # is a comment, and Python ignores it. Use comments to explain why the code does something, not to repeat what it obviously does:

# Price with sales tax for a store in Austin, Texas
price = 100
print(price * 1.0825)  # 8.25% combined state and local rate

Hands-on example: a hardware store receipt

With nothing more than print(), math and comments you can already build something useful. Main Street Hardware in Austin, Texas, wants a quick receipt that adds up a purchase and shows the sales tax. Unlike many countries, U.S. shelf prices usually don't include sales tax: it's added at the register. Create receipt.py:

# Receipt for Main Street Hardware (Austin, Texas)
# Prices don't include sales tax: it's added at checkout (8.25%)
print("=== MAIN STREET HARDWARE ===")
print("Duct tape     2 x $4.25 =", 2 * 4.25)
print("Light bulbs   3 x $3.90 =", 3 * 3.90)
print("Paint brush   1 x $9.50 =", 1 * 9.50)
subtotal = 2 * 4.25 + 3 * 3.90 + 1 * 9.50
print("Subtotal: $", round(subtotal, 2))
print("Sales tax (8.25%): $", round(subtotal * 0.0825, 2))
print("TOTAL: $", round(subtotal * 1.0825, 2))
print("Thanks for shopping with us!")

Output:

=== MAIN STREET HARDWARE ===
Duct tape     2 x $4.25 = 8.5
Light bulbs   3 x $3.90 = 11.7
Paint brush   1 x $9.50 = 9.5
Subtotal: $ 29.7
Sales tax (8.25%): $ 2.45
TOTAL: $ 32.15
Thanks for shopping with us!

Three details: subtotal = ... stores a result under a name so you can reuse it, which is a variable (next lesson); Python prints $ 29.7 instead of $29.70, which you'll fix in lesson 3; and the math checks out: $29.70 × 8.25% = $2.45 in tax, for a total of $32.15.

Share of each item in the $29.70 subtotal

Duct tape28.6%
Light bulbs39.4%
Paint brush32.0%

Indentation matters (a lot)

In Python, spaces at the start of a line aren't decoration: they tell Python which instructions belong to a block. You'll see this in detail with conditionals in lesson 4, but here's the rule for now: don't put spaces at the beginning of a line unless they belong there, or you'll get an IndentationError. The convention is 4 spaces per level, and VS Code inserts them for you when you press Tab.

2. What is indentation used for in Python?

  • To show which lines belong to a block (if, for, def…)
  • Only to make code look neat
  • To write comments

In Python, indentation has meaning: the wrong indentation changes what the program does or raises an IndentationError.

Reading errors without fear

You're going to make lots of mistakes, and that's how everyone learns. The good news is that Python tells you exactly what went wrong and on which line. For example:

print("Hello)
  File "hello.py", line 1
    print("Hello)
          ^
SyntaxError: unterminated string literal (detected at line 1)

Read the message from the bottom up: the error type (SyntaxError), the explanation (a string that was never closed) and the line number. Here, the closing quote is missing.

Anatomy of a traceback

When an error happens while the program is running (not while Python is checking the syntax), you get a traceback, a trail of what Python was doing. Suppose that on line 3 of a receipt you typed pirnt:

Traceback (most recent call last):
  File "C:\python-course\receipt.py", line 3, in <module>
    pirnt("TOTAL")
    ^^^^^
NameError: name 'pirnt' is not defined. Did you mean: 'print'?
  • File … line 3: the file and the exact line (Ctrl + click in VS Code takes you there).
  • The line of code and the ^^^^^: they point at the part that failed.
  • The last line: the error type, an explanation and even a suggestion: Did you mean: 'print'?

Lines 1 and 2 did run: Python stops at the first line that fails, so you may see part of your output and then the error.

Common beginner mistakes

Typing Print("Hello") with a capital P.

Python is case-sensitive: it's print. The error will be NameError: name 'Print' is not defined.

Copying code from Word, Google Docs or a chat app that turned the quotes into curly quotes “ ”.

Use straight quotes " ". Curly ones cause SyntaxError: invalid character '“' (U+201C).

Typing python hello.py inside interactive mode (>>>).

That command belongs in the terminal. Leave with exit() and run it there; otherwise you'll get SyntaxError: invalid syntax.

Running the file from another folder and seeing can't open file ... No such file or directory.

Move into the file's folder with cd before running it, or use VS Code's ▶ button, which does it for you.

Good habits from your very first file

Use lowercase file names with no spaces (hardware_receipt.py, not Receipt FINAL(2).py), never name a file after a Python library (random.py, pandas.py), and test in small steps: a bug in 3 new lines is easy to find; in 40, it isn't.

3. You see NameError: name 'pirnt' is not defined. What happened?

  • Python isn't installed correctly
  • There's no internet connection
  • You misspelled the name of the print function

NameError means Python doesn't know that name. The message tells you what failed and on which line, and here it even suggests the fix.

4. Your file receipt.py is in the python-course folder, but running python receipt.py shows can't open file ... [Errno 2] No such file or directory. What do you do?

  • Reinstall Python with the PATH box checked
  • Go to the file's folder with cd (or use VS Code's ▶ button) and run it again
  • Change the file extension to .txt

Python is installed (it answered with its own message); what it can't find is the file in the terminal's current folder. A PATH problem would say "'python' is not recognized as an internal or external command…"

Checklist before lesson 2

Practice exercise

Create a file called about_me.py that displays:

  1. Your name.
  2. Your city and state.
  3. The result of calculating how many minutes there are in a week.
  4. A comment line explaining the calculation.
See solution
print("My name is Jordan")
print("I live in Columbus, Ohio")
# 7 days x 24 hours x 60 minutes
print(7 * 24 * 60)

Output of the calculation: 10080. If you got an error, read the last line first: it's almost always a missing quote or parenthesis.

Summary

  • Python is an interpreted, readable and highly in-demand language used for automation, data, AI and web back ends.
  • Install it from python.org (the install manager on Windows, or the classic installer with "Add python.exe to PATH") and use VS Code as your editor.
  • print() displays information; # starts a comment for humans.
  • Indentation has meaning in Python, and U.S. prices usually need sales tax added on top.
  • Read a traceback from the bottom up: error type, explanation and exact line.

Next lesson: Python Variables, Data Types and Operators. You'll work with int, float, str and bool, convert between types and use arithmetic, comparison and logical operators.

🎓 Save your progress and get a free certificate

Create your account in 30 seconds, mark your lessons and download your certificate at the end.

Enroll for free