Python Introduction

Objectives: Python Introduction

From Abacus to Python (2025): A Friendly, Complete History & How Code Becomes Binary

From Abacus to Python (2025): History, People, and how Python becomes Binary

A clean, enjoyable set of notes that connect the dots—from the earliest calculation tools to modern Python, and the exact path your .py turns into machine code and gets saved to disk.

Big picture (the map)

Computing history is a chain of ideas: counting tools → logic & math → mechanical computers → electronic computers → machine code & assembly → high-level languages → Python. Today, Python runs on many engines (CPython, PyPy, MicroPython, Pyodide) and can be accelerated or compiled in several ways.

YOU write Python ─▶ Parser/Compiler ─▶ Python bytecode ─▶ VM / JIT / AOT ─▶ CPU machine code (.py text file) (tokenize + parse) (.pyc cache) (eval loop or (binary instructions) native compiler)

1) Timeline: from counting frames to Python in 2025

Ancient → 17th c.: Abacus & early calculators

The abacus (ancient Mesopotamia/China, refined across centuries) was the classic manual counting device—no electricity, just place-value beads guiding arithmetic thinking. :contentReference[oaicite:0]{index=0}

1800s: The idea of programmable machines

Charles Babbage designed the Analytical Engine (never fully built) with a memory store and mill (CPU). Ada Lovelace wrote what’s widely regarded as the first algorithm, anticipating general-purpose computation. :contentReference[oaicite:1]{index=1}

Meanwhile, George Boole formalized Boolean algebra—true/false logic used by every digital circuit today. :contentReference[oaicite:2]{index=2}

1930s–1940s: Computability & stored programs

Alan Turing described the universal computing model (the “Turing machine”). John von Neumann advanced the stored-program architecture that modern CPUs follow. :contentReference[oaicite:3]{index=3}

1950s–1970s: From assembly to high-level languages

Humans wrote assembly language (symbolic mnemonics) translated by an assembler to machine code 1:1. Then came higher-level languages: FORTRAN (John Backus), COBOL (Grace Hopper), and later C (Dennis Ritchie), making systems portable. :contentReference[oaicite:4]{index=4}

1991 → today: Python

Guido van Rossum created Python around 1989; first public release 1991. It emphasized readability (“executable pseudocode”) and batteries-included libraries. The Python Software Foundation (PSF) now stewards the language. Python 2 retired (EOL) in 2020; Python 3 continues to evolve. :contentReference[oaicite:5]{index=5}

2020s: Faster internals, wider platforms

CPython adopted a modern PEG parser (3.9, PEP 617), added many speedups, and continues to refine bytecode and the evaluation loop. The latest stable line is the Python 3.13 series (2024–2025). :contentReference[oaicite:6]{index=6}

Python also runs in the browser via WebAssembly (Pyodide) and on microcontrollers (MicroPython). :contentReference[oaicite:7]{index=7}

2) Binary & Assembly 101 (the foundation)

Binary Computers store and operate on 0/1 bits. Instructions are sequences of bits that a specific CPU understands—a CPU’s instruction set (e.g., ARM, x86-64). :contentReference[oaicite:8]{index=8}

Machine Code Raw numeric opcodes + operands. Fastest, but unreadable for humans. :contentReference[oaicite:9]{index=9}

Assembly A human-friendly text form of machine code (e.g., mov eax, 1). An assembler converts it to machine code for a given CPU. :contentReference[oaicite:10]{index=10}

; Assembly example (x86-64 idea)


mov rax, 2
add rax, 3
; After assembling: becomes binary opcodes the CPU executes

Key idea: every higher-level language (Python, C, Java…) must eventually end up as binary machine instructions for the target CPU.

3) How Python actually runs: from .py → bytecode → machine code

CPython (the reference implementation most people use)

  1. Source: You write a .py file (text).
  2. Lex & Parse: CPython tokenizes and parses your code (since 3.9, a PEG parser per PEP 617) to build an AST. :contentReference[oaicite:11]{index=11}
  3. Compile to bytecode: CPython compiles the AST into Python bytecode instructions (a portable, VM-friendly instruction set). :contentReference[oaicite:12]{index=12}
  4. Execute: The CPython evaluation loop interprets bytecode, running C implementations of Python opcodes and the standard library. :contentReference[oaicite:13]{index=13}
  5. Cache: On import, CPython stores compiled bytecode in __pycache__/*.pyc for faster future imports (it auto-invalidates when the source changes). You can disable writing bytecode with -B or PYTHONDONTWRITEBYTECODE. :contentReference[oaicite:14]{index=14}
your_script.py │ tokenize → parse (PEG) → AST ├─▶ compile ─▶ bytecode (in memory) │ └─ optionally cached as __pycache__/module.cpython-3x.pyc └─▶ eval loop executes opcodes (C code under the hood) → OS → CPU

Note: Bytecode is not machine code; it’s instructions for the Python virtual machine. The VM itself is C code that the CPU runs natively.

Other engines and compilers (how Python can become native)

  • PyPy (a Python interpreter with a JIT) can compile hot bytecode paths to native machine code at runtime for big speedups on certain workloads. :contentReference[oaicite:15]{index=15}
  • Numba JIT-compiles numeric Python functions (subset of Python/NumPy) to machine code via LLVM, typically with @jit decorators. :contentReference[oaicite:16]{index=16}
  • Cython compiles Python-like code (with optional C types) into C, which then builds a CPython extension module. :contentReference[oaicite:17]{index=17}
  • mypyc compiles typed Python modules to C extensions (used to speed up mypy). :contentReference[oaicite:18]{index=18}
  • Nuitka is an ahead-of-time compiler that turns Python programs into optimized C/C++ and then native binaries. :contentReference[oaicite:19]{index=19}
  • Pyodide brings CPython to WebAssembly, running Python in the browser; MicroPython runs Python on microcontrollers (e.g., Raspberry Pi Pico). :contentReference[oaicite:20]{index=20}

4) “How does it get saved as binary?” (storage path)

  1. Your source is plain text on disk (.py), saved by your editor/IDE.
  2. When a module is imported, CPython may write a .pyc file in __pycache__/ containing a serialized form of the compiled bytecode + metadata (e.g., magic number, timestamps). :contentReference[oaicite:21]{index=21}
  3. If you build an executable with a compiler like Nuitka or package with other tools, the final artifact contains native machine code (and/or a bundled interpreter). That machine code is just bytes on disk—i.e., binary. :contentReference[oaicite:22]{index=22}
  4. At runtime, the operating system loads the executable or the CPython interpreter into memory, maps code/data pages, and the CPU executes machine instructions.

Takeaway: everything ends up as bytes on disk and bytes in memory. The magic is how we translate from human-friendly Python to CPU-friendly instructions.

5) Modern Python (2025) — what’s “latest”?

  • Active series: Python 3.13 (released in late 2024, with ongoing 3.13.x updates in 2025). It brings parser/runtime improvements and many smaller features/perf wins. Always check “What’s New” for details. :contentReference[oaicite:23]{index=23}
  • Docs to know: dis (bytecode), importlib (import system), compileall, and PEP 8 (style guide). :contentReference[oaicite:24]{index=24}
  • Bytecode caches: __pycache__, configurable via PYTHONPYCACHEPREFIX (3.8+). :contentReference[oaicite:25]{index=25}
  • New frontiers: WASM targets (Pyodide) and embedded Python (MicroPython) keep expanding where Python can run. :contentReference[oaicite:26]{index=26}

6) Quick Q&A (teach your future self)

Is Python compiled or interpreted?

Both ideas appear: CPython compiles to Python bytecode, then interprets that bytecode. Alternative engines may JIT or AOT-compile parts to native machine code. :contentReference[oaicite:27]{index=27}

Does Python use assembly?

Not directly for your code. Your Python becomes bytecode; the interpreter (written in C) runs on the OS/CPU. JIT/AOT tools can produce native machine code (which the CPU executes—i.e., “assembly level” instructions under the hood). :contentReference[oaicite:28]{index=28}

What happens when I run python myapp.py?

  1. Interpreter starts → reads source → parses (PEG) → compiles to bytecode.
  2. Executes bytecode in the evaluation loop (calls into C/OS/hardware as needed).
  3. On imports, writes/reads .pyc in __pycache__ for speed. :contentReference[oaicite:29]{index=29}

7) People & terms to remember (cheat list)

Ada Lovelace Charles Babbage George Boole Alan Turing John von Neumann John Backus Grace Hopper Dennis Ritchie Guido van Rossum

Plus: Assembler, Machine code, Bytecode, Virtual Machine, JIT, AOT, WASM, PEP, PSF. :contentReference[oaicite:30]{index=30}

References (for deeper reading)

  • Abacus; Ada Lovelace; Babbage; Boole — Encyclopædia Britannica. :contentReference[oaicite:31]{index=31}
  • Turing; von Neumann architecture — Britannica. :contentReference[oaicite:32]{index=32}
  • Assembly & machine code definitions — Wikipedia. :contentReference[oaicite:33]{index=33}
  • Python internals (bytecode, parser, import system) — Python docs. :contentReference[oaicite:34]{index=34}
  • __pycache__ & .pyc behavior — Python tutorial & What’s New 3.8. :contentReference[oaicite:35]{index=35}
  • Python history & PSF — Python.org / Python Software Foundation. :contentReference[oaicite:36]{index=36}
  • Latest line (3.13 series) — Python “What’s New / versions” pages. :contentReference[oaicite:37]{index=37}
  • Alternative engines/compilers: PyPy, Numba, Cython, mypyc, Nuitka. :contentReference[oaicite:38]{index=38}
  • Python in the browser & on microcontrollers: Pyodide, MicroPython. :contentReference[oaicite:39]{index=39}

Tip: Pair these notes with the official “dis” module to peek at Python bytecode (python ->> import dis; dis.dis(fn)) and connect concepts to real instructions. :contentReference[oaicite:40]{index=40}

Python Introduction

Python Introduction

What is Python?

Python is a popular programming language. It was created by Guido van Rossum and released in 1991.

Python is used for:

  • Web development (server-side)
  • Software development
  • Mathematics
  • System scripting

What Can Python Do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems and modify files.
  • Python can handle big data and perform complex mathematics.
  • Python is good for rapid prototyping or production-ready software development.

Why Python?

  • Python works on different platforms: Windows, Mac, Linux, Raspberry Pi, etc.
  • Python has a simple syntax similar to English language.
  • Python allows developers to write programs with fewer lines than other languages.
  • Python runs on an interpreter system, meaning code can be executed immediately.
  • Python supports multiple programming styles: procedural, object-oriented, and functional.

Good to Know

  • The most recent major version of Python is Python 3, which we use in this tutorial.
  • Python 2 is still used but only receives security updates.
  • Python can be written in a text editor or in an Integrated Development Environment (IDE) like Thonny, PyCharm, NetBeans, or Eclipse.

Python Syntax Compared to Other Languages

  • Python is designed for readability and is similar to English and math.
  • Python uses new lines to complete a command instead of semicolons or parentheses.
  • Python uses indentation (whitespace) to define the scope of loops, functions, and classes.
  • Other languages often use curly brackets { } for scope.

Example: Your First Python Program

Print "Hello, World!" on the screen:

print("Hello, World!")

Python Code Execution

Python code runs on an interpreter. This means you can write your code and run it immediately without compiling first. This is useful for testing ideas quickly.

Summary

  • Python is simple, readable, and widely used for many purposes.
  • It supports multiple programming paradigms.
  • Python is ideal for beginners and professionals alike.
  • Indentation is very important in Python; it defines code blocks.

Reference Book: N/A

Author name: MWALA_LEARN Work email: biasharabora12@gmail.com
#MWALA_LEARN Powered by MwalaJS #https://mwalajs.biasharabora.com
#https://educenter.biasharabora.com

:: 1::