Python was conceived in the late 1980s by Guido van Rossum at the Centrum Wiskunde & Informatica (CWI) in the Netherlands as a successor to the ABC programming language. Officially released in February 1991, Python was architected around readability, explicit syntax (as articulated in Tim Peters' The Zen of Python, PEP 20), and dynamic multi-paradigm flexibility supporting procedural, object-oriented, and functional programming methodologies.
- Interpreted & Hybrid Execution: Unlike pure compiled languages (such as C/C++) that produce native machine binaries, or pure interpreters that interpret source lines on the fly, standard Python (CPython) compiles source code into an intermediate, optimized format known as bytecode before executing it on a runtime virtual machine.
- Dynamically Typed: Variable types are not declared explicitly by the programmer; instead, data types are bound dynamically to runtime objects rather than variable names.
- Automatic Memory Management: CPython integrates reference counting coupled with a generational cyclic garbage collector to track object lifetimes and reclaim orphaned heap memory automatically.
- Batteries Included Standard Library: Comprehensive built-in support for mathematical operations, file I/O, regular expressions, networking, serialization, and cryptographic hashing without third-party dependencies.
The execution of a Python script follows a rigorous, multi-tiered compilation and runtime pipeline:
| Pipeline Stage | Component / Process | Artifact & Architectural Function |
|---|---|---|
| 1. Lexical Analysis | Tokenizer & Scanner | Converts raw UTF-8 source characters into discrete language tokens (keywords, identifiers, literals, operators, punctuation, and indentation tokens INDENT / DEDENT). |
| 2. Syntactic Parsing | Parser & Grammar Engine | Validates language syntax against Python's PEG grammar and generates an in-memory Abstract Syntax Tree (AST). Syntax errors are raised at this phase prior to execution. |
| 3. Bytecode Compilation | CPython Code Generator | Compiles the AST into platform-independent intermediate instructions known as bytecode. These instructions are cached as .pyc files in the pycache directory with magic version headers. |
| 4. Virtual Machine Runtime | Python Virtual Machine (PVM) | A stack-based interpreter loop (ceval.c in CPython) that consumes bytecode instructions sequentially, manages execution frames, and executes low-level CPU machine calls. |
Python eliminates traditional code block delimiters such as curly braces {} or begin...end keywords found in C or Pascal. Instead, Python employs Syntactic Indentation:
- Whitespace & Indentation (PEP 8): A block of code is delineated strictly by consistent leading whitespace. PEP 8 mandates exactly 4 spaces per indentation level. Tabs and spaces must never be mixed (enforced via
TabErrorin Python 3). - Identifiers & Naming Conventions: Identifiers must commence with an alphabet (
[a-zA-Z]) or an underscore (_), followed by alphanumeric characters or underscores. They are strictly case-sensitive (e.g.,totalScoreandTotalScoreare separate identifiers). Reserved keywords (e.g.,def,class,if,lambda,yield,async) cannot serve as identifiers. - Comments & Docstrings: Single-line comments commence with
#and are discarded during lexical analysis. Multi-line documentation strings (docstrings) are defined using triple-quoted string literals ("""..."""or'''...''') placed immediately below function, class, or module headers, accessible at runtime via the.docattribute. - Interactive Mode (REPL) vs. Script Mode: In Interactive Mode, Python executes a Read-Eval-Print Loop (REPL), ideal for immediate expression evaluation and debugging. In Script Mode, complete source files (
.py) are executed from start to finish via command-line invocations:python script.py.