In the previous tutorial, we learned what Python is and why it is worth learning. Now it is time to install it and write your first program.

By the end of this tutorial, you will have Python running on your computer. You will know how to use the Python REPL, write a script, and run it from the terminal.

Installing Python

Python works on macOS, Linux, and Windows. Let me show you how to install it on each system.

Check If You Already Have Python

Open your terminal (or Command Prompt on Windows) and type:

python3 --version

If you see something like Python 3.12.x or Python 3.13.x, you are ready. Skip to the “The Python REPL” section.

If you see an error or a version older than 3.12, follow the installation steps below.

macOS

The easiest way is with Homebrew:

brew install python

This installs the latest Python 3. After installation, verify:

python3 --version

If you do not have Homebrew, go to python.org/downloads and download the macOS installer.

Linux (Ubuntu / Debian)

Most Linux systems come with Python pre-installed. But it may be an older version. To install the latest:

sudo apt update
sudo apt install python3 python3-pip python3-venv

Verify:

python3 --version

Windows

Go to python.org/downloads and download the Windows installer.

Important: During installation, check the box that says “Add Python to PATH.” This is the most common mistake beginners make on Windows. Without it, you cannot run Python from the terminal.

After installation, open Command Prompt and type:

python --version

On Windows, the command is usually python instead of python3.

Alternative: Install with uv

uv is a modern Python package manager that can also install Python itself. It is 10-100x faster than pip. If you want to try the modern approach:

# Install uv (macOS/Linux)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install Python with uv
uv python install 3.13

We will cover uv in more detail in a later tutorial. For now, the standard installation is fine.

The Python REPL

REPL stands for Read-Eval-Print Loop. It is an interactive mode where you type Python code and see the result immediately.

Start the REPL by typing python3 in your terminal:

python3

You will see something like this:

Python 3.13.0 (default, Oct  7 2024, 00:00:00)
[GCC 14.2.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> is the prompt. It means Python is waiting for your input.

Try typing some expressions:

>>> 2 + 3
5
>>> "Hello" + " " + "World"
'Hello World'
>>> 10 * 5
50
>>> type(42)
<class 'int'>
>>> type("hello")
<class 'str'>

The REPL evaluates each line and prints the result. This is great for testing small pieces of code.

To exit the REPL, type exit() or press Ctrl + D (macOS/Linux) or Ctrl + Z then Enter (Windows).

The REPL is useful for quick tests. But for real programs, you want to write scripts.

Your First Script

A Python script is a text file with a .py extension. Let me create one.

Open your text editor and create a file called hello.py:

print("Hello, World!")

Save the file and run it from the terminal:

python3 hello.py

Output:

Hello, World!

That is it. You just wrote and ran your first Python program.

A Bigger Program

Let me show you a more interesting program. Create a file called first_program.py:

# This is a comment — Python ignores lines that start with #

# Print a greeting
print("Hello, World!")

# Do some math
print(f"2 + 3 = {2 + 3}")
print(f"10 - 4 = {10 - 4}")
print(f"3 * 7 = {3 * 7}")
print(f"15 / 4 = {15 / 4}")       # Float division: 3.75
print(f"15 // 4 = {15 // 4}")     # Integer division: 3
print(f"2 ** 8 = {2 ** 8}")       # Power: 256

# Work with strings
greeting = "Hello"
name = "Alex"
print(f"{greeting}, {name}!")

# Check your Python version
import sys
print(f"You are running Python {sys.version}")

Run it:

python3 first_program.py

Output:

Hello, World!
2 + 3 = 5
10 - 4 = 6
3 * 7 = 21
15 / 4 = 3.75
15 // 4 = 3
2 ** 8 = 256
Hello, Alex!
You are running Python 3.13.0

Let me explain what is happening:

  • print() displays text on the screen.
  • Lines starting with # are comments. Python ignores them.
  • f"..." is an f-string. It lets you put variables inside curly braces {}.
  • import sys loads the sys module so we can check the Python version.
  • // is integer division (rounds down). / is regular division.
  • ** is the power operator. 2 ** 8 means 2 to the power of 8.

Getting User Input

Python can ask the user for input:

name = input("What is your name? ")
print(f"Hello, {name}! Welcome to Python.")

Run it and type your name when asked:

What is your name? Alex
Hello, Alex! Welcome to Python.

The input() function waits for the user to type something and press Enter. It always returns a string. If you need a number, you have to convert it:

age_text = input("How old are you? ")
age = int(age_text)  # Convert string to integer
print(f"In 10 years, you will be {age + 10}.")

We will learn more about type conversions in the next tutorial.

Setting Up VS Code

You can write Python in any text editor. But Visual Studio Code (VS Code) is the most popular choice. Here is how to set it up.

Step 1: Install VS Code

Go to code.visualstudio.com and download VS Code for your operating system.

Step 2: Install the Python Extension

Open VS Code and go to Extensions (the square icon on the left sidebar). Search for “Python” and install the one by Microsoft. It has millions of downloads.

This extension gives you:

  • Syntax highlighting — code is colored for readability
  • IntelliSense — autocomplete suggestions as you type
  • Linting — warnings about potential errors
  • Debugging — step through your code line by line
  • Run button — run Python files with one click

Step 3: Select the Python Interpreter

Press Ctrl + Shift + P (or Cmd + Shift + P on macOS) and type “Python: Select Interpreter.” Choose the Python version you installed.

Step 4: Create and Run a File

  1. Create a new file: File > New File
  2. Save it as hello.py
  3. Type print("Hello from VS Code!")
  4. Click the play button (triangle icon) in the top right
  5. You should see the output in the terminal panel

Running Python Files

There are several ways to run Python:

From the terminal

python3 my_script.py

This is the most common way. You type the command and see the output.

From VS Code

Click the play button or press F5 to run with the debugger. The output appears in the terminal panel at the bottom.

One-liner from the terminal

For quick tests, you can run code without creating a file:

python3 -c "print('Hello from the command line!')"

The REPL

For interactive testing:

python3
>>> print("Hello from the REPL!")

Online Alternatives

If you cannot install Python on your computer, you can use these online tools:

These are fine for learning, but I recommend installing Python locally. You will need it for later tutorials when we work with files, packages, and virtual environments.

Python File Basics

Before we cover common mistakes, let me explain a few things about Python files.

Comments

Comments start with #. Python ignores everything after # on that line:

# This is a comment
print("Hello")  # This is also a comment

Use comments to explain why your code does something, not what it does. Good code is self-explanatory. Comments explain the reasoning behind decisions.

Semicolons

Python does not need semicolons at the end of lines. Each line is one statement:

# Python — clean
name = "Alex"
age = 25

# Java/C++ — semicolons required
# String name = "Alex";
# int age = 25;

You can put multiple statements on one line with semicolons, but do not do it. It hurts readability:

# BAD: hard to read
name = "Alex"; age = 25; print(name)

# GOOD: one statement per line
name = "Alex"
age = 25
print(name)

Indentation

Python uses indentation (spaces) to define code blocks. Other languages use curly braces {}. Python uses 4 spaces per level:

if True:
    print("This is indented")
    if True:
        print("This is double indented")

Never mix tabs and spaces. Configure your editor to use 4 spaces for indentation. VS Code does this automatically with the Python extension.

Case Sensitivity

Python is case-sensitive. Name, name, and NAME are three different variables:

name = "Alex"
Name = "Sam"
NAME = "Jordan"

print(name)   # Alex
print(Name)   # Sam
print(NAME)   # Jordan

By convention, use lowercase with underscores for variables and functions: user_name, total_count, calculate_average. We will cover naming conventions as we go.

Common Mistakes

python vs python3

On some systems, python points to Python 2 (or does not exist). Always use python3 to make sure you run the correct version:

python3 my_script.py

Forgetting to Add Python to PATH (Windows)

If you see “python is not recognized as an internal or external command,” Python is not in your PATH. The easiest fix is to reinstall Python and check the “Add Python to PATH” box.

File Not Found

If you get “No such file or directory,” make sure you are in the correct directory. Use cd to navigate:

cd /path/to/your/project
python3 hello.py

IndentationError

Python uses indentation (spaces) instead of curly braces to define code blocks. If you mix tabs and spaces, you will get errors. Configure your editor to use 4 spaces for indentation.

Your Second Program: Temperature Converter

Let’s write a slightly more complex program. Create a file called converter.py:

# converter.py — Convert Celsius to Fahrenheit and back

celsius = 25
fahrenheit = celsius * 9 / 5 + 32
print(f"{celsius}°C = {fahrenheit}°F")

fahrenheit = 98.6
celsius = (fahrenheit - 32) * 5 / 9
print(f"{fahrenheit}°F = {celsius:.1f}°C")

Output:

25°C = 77.0°F
98.6°F = 37.0°C

This program uses variables, math, and f-strings. We will learn more about each of these in the next tutorial.

Useful Terminal Commands

Here are some terminal commands you will use often when working with Python:

python3 --version          # Check Python version
python3 file.py            # Run a Python file
python3 -c "print('hi')"  # Run a one-liner
python3                    # Start the REPL
pip install package_name   # Install a package (more in Tutorial #8)
pip list                   # List installed packages

Source Code

You can find the code for this tutorial on GitHub:

kemalcodes/python-tutorial — tutorial-02-installation

What’s Next?

In the next tutorial, we will learn about variables, data types, and f-strings. You will learn how Python handles numbers, text, and boolean values.