Python Introduction

What Python is, why it is so popular, and how to install it and run your first script.

What is Python?

Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum and first released in 1991. It's dynamically typed (you don't declare variable types up front) and garbage-collected (you never manually free memory), and it puts a heavy emphasis on code readability — Python code tends to read almost like structured English.

Python
def greet(name):
    return f"Hello, {name}!"

print(greet("World"))  # Hello, World!

There's no boilerplate here — no class wrapper required, no explicit type declarations, no semicolons. That's Python's whole design philosophy in miniature.

  • Readability — Python enforces indentation as syntax, so codebases tend to look consistent across different authors. The language's own guiding philosophy (import this, the "Zen of Python") explicitly values readability over cleverness.
  • A huge ecosystem — the Python Package Index (PyPI) hosts hundreds of thousands of packages. Need to parse a CSV, hit an HTTP API, train a neural network, or scrape a web page? There's almost certainly a mature, well-documented library already.
  • General-purpose, not niche — Python is genuinely competitive across very different domains:
    • Web backends — Django, Flask, FastAPI.
    • Data science & machine learning — pandas, NumPy, scikit-learn, PyTorch, TensorFlow.
    • Scripting & automation — build tools, DevOps scripts, file processing, CI pipelines.
    • Scientific computing — used heavily in academia, finance, and research.
  • Gentle learning curve — the syntax gets out of the way, which is why Python is the most common first language taught in university courses today.
  • Massive hiring demand — data science, backend, automation, and ML roles overwhelmingly list Python as a required or preferred skill.

Installing Python 3

Modern Python is always Python 3 — Python 2 reached end-of-life in January 2020 and should not be used for new projects.

  • Windows — download the installer from python.org, and make sure to check "Add python.exe to PATH" during setup.
  • macOSbrew install python3 (via Homebrew), or the official installer from python.org.
  • Linux — usually preinstalled; otherwise sudo apt install python3 (Debian/Ubuntu) or your distro's package manager.

Verify the install from a terminal:

Bash
python3 --version
# Python 3.12.4

On Windows, the launcher is sometimes just python instead of python3 — either works as long as it points at a Python 3.x install.

Your first script

Save this as hello.py:

Python
print("Hello, World!")

Run it from the terminal:

Bash
python3 hello.py
# Hello, World!

No compilation step, no build artifact — the interpreter reads and executes the file directly, top to bottom.

The interactive REPL

Running python3 with no filename drops you into the REPL (Read-Eval-Print Loop) — an interactive shell that's invaluable for quickly testing an idea:

Bash
python3
Python
>>> 2 + 2
4
>>> name = "Ada"
>>> print(f"Hi, {name}")
Hi, Ada
>>> exit()

Every line you type is evaluated immediately, and the result of an expression (not a statement) is printed automatically — this tight feedback loop is one reason Python feels so approachable for experimentation.

Real-world example

Instagram's backend, large parts of Netflix's internal tooling, Dropbox's original desktop client, and virtually every modern data science and machine learning pipeline (via pandas, NumPy, and PyTorch) run on Python. It's also the dominant language for introductory computer science education worldwide.

Common mistakes

  • Installing Python 2 out of habit or following an outdated tutorial — always target Python 3.
  • Forgetting to add Python to your system PATH on Windows, so python3 isn't recognized in a terminal.
  • Mixing tabs and spaces for indentation in the same file — Python 3 treats this as a syntax error, not a style nitpick.

Interview questions

Q: Is Python compiled or interpreted? Technically both: the CPython interpreter (the standard implementation) first compiles source code to an intermediate bytecode (.pyc files), which the Python Virtual Machine then interprets. There's no separate build step you have to run yourself, which is why Python feels purely interpreted in everyday use.

Q: Why did Python 2 vs Python 3 matter so much? Python 3 (released 2008) fixed several long-standing design inconsistencies — most notably making all strings Unicode by default and changing print from a statement to a function — but broke backward compatibility, so the ecosystem took over a decade to fully migrate. Python 2 reached official end-of-life in 2020 and no longer receives security updates.