Last updated: 2026-05-21

Introduction to Python

Python is a high-level, general-purpose programming language created by Guido van Rossum and first released in 1991. It was designed with a single guiding philosophy: code should be readable, simple, and expressive. Where other languages optimise for performance or strict type safety, Python optimises for developer productivity and clarity. The result is a language that reads almost like plain English and can be learned faster than almost any other.

Today, Python is one of the most widely used programming languages in the world. It is the dominant language in data science, machine learning, and artificial intelligence. It is widely used for backend web development, automation, scripting, and scientific computing. According to the TIOBE Index and Stack Overflow's annual developer surveys, Python has consistently ranked among the top two or three most popular languages globally for several years running.


The Philosophy Behind Python

Python's design is guided by a set of principles collectively known as The Zen of Python, written by Tim Peters. You can read them by running import this in any Python interpreter. A few of the most influential:

Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Readability counts.

These are not just aspirational statements — they actively shaped Python's syntax. Python uses indentation to define code blocks instead of curly braces. It avoids ceremony and boilerplate. It prefers one obvious way to do something over many competing approaches.

This philosophy is why Python code written by different developers tends to look similar, and why Python is widely recommended as a first programming language.


What Python Is Used For

Python's versatility is one of its defining characteristics. It is used across more domains than almost any other language:

DomainWhat Python does thereNotable tools
Data Science & AnalyticsData manipulation, analysis, and visualisationpandas, NumPy, Matplotlib
Machine Learning & AIBuilding and training modelsTensorFlow, PyTorch, scikit-learn
Web DevelopmentBackend servers and APIsFlask, Django, FastAPI
Automation & ScriptingAutomating repetitive tasks, file operationsBuilt-in libraries
Scientific ComputingSimulations, mathematical computationSciPy, SymPy
DevOps & InfrastructureConfiguration management, deployment scriptsAnsible, Fabric
CybersecurityPenetration testing, security toolsScapy, Impacket

This range is why Python is sometimes described as a "glue language" — it connects systems, processes data between them, and automates the work around them as readily as it powers the systems themselves.


Python vs. JavaScript — The Key Differences

Since this platform already covers JavaScript in depth, understanding how Python differs from it gives you an immediate frame of reference.

JavaScriptPython
Primary environmentBrowser (and Node.js for server)Server, scripts, data science
TypingDynamic, weakly typedDynamic, strongly typed
SyntaxCurly braces {}, semicolons ;Indentation, no semicolons
ConcurrencyEvent loop, async/awaitasyncio, threading, multiprocessing
Package managernpm / yarnpip
Main use casesWeb frontend, full-stackData science, ML, backend, automation
OOP modelPrototype-based + classesClass-based

The most important practical difference for someone coming from JavaScript: Python uses indentation to define structure, not curly braces. Indentation is not optional or cosmetic — it is syntax. A wrong indent is a syntax error.


Python 2 vs. Python 3

Python has two major version lines. Python 2 was the dominant version for many years but reached its official end of life on January 1, 2020 — it no longer receives security updates or bug fixes.

Python 3 is the current, actively maintained version and the only version you should use. All new projects, all major libraries, and all documentation are Python 3. If you encounter Python 2 code in the wild — you will recognise it by print "hello" without parentheses — know that it is legacy code running on an unsupported version.

Throughout this series, all examples use Python 3.


How Python Runs

Python is not compiled to machine code the way C or Go is. When you run a Python script, the Python interpreter:

  1. Compiles the source code to bytecode — a lower-level intermediate representation stored in .pyc files.
  2. Executes the bytecode on the Python Virtual Machine (PVM).

This process is mostly invisible to the developer. You write a .py file, run it, and Python handles the rest. The implication is that Python is slower than compiled languages for CPU-intensive work — but for most applications, this difference does not matter in practice.

The most common Python implementation is CPython — the reference implementation written in C. Other implementations exist, such as PyPy (which uses JIT compilation for significantly better performance) and Jython (which runs on the Java Virtual Machine).


The Python Interpreter and REPL

One of Python's most useful features for learning and experimentation is its interactive interpreter — the REPL (Read-Eval-Print Loop). Open a terminal and type python3 to start it:

$ python3
Python 3.12.0 (default, Oct  2 2023, 09:12:02)
>>> 

At the >>> prompt, you can type any Python expression or statement and see the result immediately:

>>> 2 + 2
4
>>> name = "Wariz"
>>> f"Hello, {name}"
'Hello, Wariz!'
>>> [x ** 2 for x in range(5)]
[0, 1, 4, 9, 16]

The REPL is invaluable for testing small pieces of code, exploring libraries, and understanding how Python behaves. Use it constantly while learning.


Installing Python

macOS

macOS ships with an older Python version. Install the current version via the official installer at https://python.org/downloads or using Homebrew:

brew install python

Verify the installation:

python3 --version
# Python 3.x.x

Linux

Most Linux distributions ship with Python 3 pre-installed. If not:

# Debian/Ubuntu
sudo apt install python3

# Fedora
sudo dnf install python3

Windows

Download the installer from https://python.org/downloads. During installation, check "Add Python to PATH" — without this, the python command will not be available in the terminal.

Verify:

python --version
# Python 3.x.x

pip — Python's Package Manager

pip is Python's built-in package manager — the equivalent of npm in the JavaScript ecosystem. It installs packages from the Python Package Index (PyPI), which hosts over 500,000 open source packages.

pip install requests          # Install a package
pip install requests==2.31.0  # Install a specific version
pip uninstall requests        # Uninstall a package
pip list                      # List installed packages
pip freeze                    # List installed packages with exact versions

Virtual environments

When working on multiple Python projects, each may require different versions of the same package. Virtual environments solve this by creating an isolated Python environment per project — packages installed in one project's virtual environment do not affect others.

# Create a virtual environment
python3 -m venv venv

# Activate it
source venv/bin/activate      # macOS/Linux
venv\Scripts\activate         # Windows

# Install packages (only affects this environment)
pip install flask

# Deactivate when done
deactivate

The convention is to name the virtual environment folder venv and add it to .gitignore so it is not committed to the repository.

requirements.txt

The equivalent of package.json in Python projects is a requirements.txt file — a plain text list of dependencies and their versions:

# Generate it from the current environment
pip freeze > requirements.txt

# Install all dependencies from it (e.g. when cloning a project)
pip install -r requirements.txt

Running a Python Script

Write a Python file with a .py extension and run it from the terminal:

python3 hello.py

A common convention in Python scripts is the if __name__ == "__main__" guard — it ensures that certain code only runs when the script is executed directly, not when it is imported as a module by another script:

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

if __name__ == "__main__":
    print(greet("Wariz"))

This pattern will appear frequently as the series progresses.


Why Python Is Worth Learning Alongside JavaScript

JavaScript owns the browser and is the language of the web frontend. Python owns data, automation, and an increasingly large share of the backend. Together they cover an enormous range of what software developers actually build.

A developer who knows both can:

  • Build a web frontend in JavaScript and a data-processing backend in Python.
  • Automate development workflows in Python while building the application in JavaScript.
  • Work across web development, data engineering, and machine learning without switching stacks entirely.

Python is not a replacement for JavaScript — it is a complement to it. The two languages together make a developer significantly more versatile.