Python

On this page 7

Python is a high-level, general-purpose programming language with dynamic typing, automatic memory management and a syntax that uses indentation to define code blocks. Created by Guido van Rossum and first released in 1991, it has become one of the most widely used programming languages, especially for data analysis, machine learning, automation, scripting and web back ends.

Among the major languages in programming, Python is defined by a clear design priority: readability and developer productivity over raw execution speed. Its standard library and package ecosystem let developers solve many problems with little code, while performance-critical work is usually delegated to libraries written in C, C++ or Rust.

How Python code is executed

Python source code is compiled to bytecode and then interpreted by a virtual machine. In CPython, the reference implementation written in C, each module is compiled into bytecode instructions, cached in .pyc files, and executed by an evaluation loop. There is no separate build step for the developer, which keeps the edit-run cycle short.

CPython manages memory with reference counting plus a cycle-detecting garbage collector. Every object carries a count of references to it and is freed when that count reaches zero, while the collector periodically finds groups of objects that refer only to each other.

Historically, CPython used a global interpreter lock (GIL) that allows only one thread to execute Python bytecode at a time. Threads still help with waiting on network or disk, but CPU-bound work traditionally needed multiple processes to use several cores. Since version 3.13, CPython offers an optional free-threaded build without the GIL, which is gradually maturing alongside an experimental just-in-time compiler.

Several implementations of the language exist, each suited to a different environment.

ImplementationWritten inKey characteristicTypical use
CPythonCReference implementation, widest compatibilityDefault choice for almost all projects
PyPyRPythonTracing JIT compiler, often much faster on pure Python loopsLong-running pure-Python workloads
MicroPythonCSmall subset for devices with very little memoryMicrocontrollers and embedded boards
GraalPyJavaRuns on the GraalVM and interoperates with JVM languagesEmbedding Python in Java systems
Main Python implementations

Core characteristics of the language

Python is dynamically but strongly typed: variables do not declare types, yet the interpreter refuses to mix incompatible values silently, so "3" + 4 raises a TypeError instead of guessing. It follows duck typing, meaning that an object is usable wherever it provides the required methods, regardless of its class.

  • Significant indentation replaces braces, so the visual structure of the code is its actual structure.
  • Multiple paradigms are supported: procedural, object-oriented and many functional techniques such as comprehensions and first-class functions.
  • Optional type hints, introduced in Python 3.5, are ignored at run time but checked by external tools such as mypy or pyright.
  • Batteries included: the standard library covers files, networking, JSON, regular expressions, testing, concurrency and more.

Language changes go through Python Enhancement Proposals (PEPs). PEP 8 defines the community style guide, and since 2019 a five-member steering council elected by core developers decides on proposals. New feature releases arrive once a year, each October, and each version receives about five years of bug-fix and security support.

Python compared with other major languages

Python is usually chosen for speed of development, while compiled languages are chosen for speed of execution or strict guarantees. The comparison below summarizes where it stands against neighbors in the same family of languages.

LanguageTypingExecution modelTypical strength
PythonDynamic, optional hintsBytecode interpreterData science, automation, rapid development
JavaScriptDynamicJIT-compiled engineBrowser front ends and Node.js services
JavaStaticJVM bytecode with JITLarge enterprise back ends
GoStaticNative compilationNetwork services and command-line tools
RustStaticNative compilation, no garbage collectorSystems code with memory safety
C++StaticNative compilationGames, engines, high-performance computing
Python versus other widely used languages

For tight loops written in pure Python, CPython is often one to two orders of magnitude slower than equivalent C code. In practice this gap matters less than it seems, because heavy numeric work runs inside compiled extensions such as NumPy, where Python only orchestrates the calls.

Where Python is used

Python dominates fields where expressiveness and libraries matter more than milliseconds. Its package index, PyPI, hosts hundreds of thousands of projects that are installed with pip or similar tools.

AreaRepresentative librariesWhy Python fits
Data analysispandas, NumPy, PolarsConcise data manipulation backed by fast native code
Machine learningPyTorch, scikit-learn, TensorFlowResearch and production share one language
Web back endsDjango, Flask, FastAPIFast development of APIs and sites
Automation and scriptingStandard library, AnsibleShort scripts replace manual operations
Scientific computingSciPy, Matplotlib, JupyterInteractive exploration and plotting
Main application areas

Limitations and common pitfalls

Python is a weak fit for hard real-time systems, mobile apps and browser front ends, and its start-up time and memory use are higher than those of compiled languages. Type errors that a compiler would catch may surface only at run time unless the team uses type hints with a static checker.

PitfallWhat goes wrongRemedy
Mutable default argumentA default list is shared across callsUse None and create the list inside
Global package installsProjects break each other’s dependenciesUse a virtual environment per project
Threads for CPU workNo speedup under the GILUse processes or native extensions
Unpinned dependenciesA new release breaks the buildPin versions in a lock file
Frequent Python pitfalls

The end of Python 2 support in January 2020 also left a long tail of legacy code. Any new project should target a currently supported Python 3 release.

In simple terms

Python is a programming language designed to read almost like plain English. Instructions are short, the layout of the text shows how the program is organized, and many common tasks are already solved by ready-made building blocks.

The trade-off is speed: Python itself is slower than languages that are translated directly into machine instructions. For most tasks this does not matter, because the heavy lifting is done by fast libraries while Python acts as the conductor.

A practical example

A finance team receives about 120 spreadsheet exports from regional offices every month and spends two working days merging them by hand. An analyst writes a Python script of roughly 150 lines that reads every file with pandas, normalizes column names and currencies, flags rows with missing invoice numbers and writes one consolidated report.

The script runs in under a minute on a laptop. The team schedules it to run automatically on the first working day of each month, keeps it in version control with pinned dependencies, and turns two days of manual work into a short review of the flagged exceptions.