Skip to content

Python - Wyatt's Notes

Python programming language notes covering fundamentals, advanced concepts, and practical examples.

sources:

  • text: Standard textbook reference

Python is a programming language with a rich type system and ecosystem. These notes cover the language from fundamentals to advanced topics, with worked examples, practice problems, and flashcards.

Topics

Intuition

Python’s philosophy emphasises readability and simplicity: The Zen of Python (“Readability counts,” “Simple is better than complex”) guides language design. This philosophy makes Python code maintainable and collaborative.

Why it matters: Python’s versatility spans data science, web development, automation, and education. It is the most taught programming language in universities.

The key insight: Python’s dynamic typing and interpreted nature make it excellent for rapid prototyping but require discipline (type hints, testing) for large projects.

What You Will Find

  • Fundamentals: Types, functions, control flow, and error handling
  • Data Structures: Lists, dictionaries, sets, tuples, and comprehensions
  • Object-Oriented: Classes, decorators, descriptors, and the data model
  • Standard Library: Essential modules (os, sys, collections, itertools, pathlib)
  • Async Programming: asyncio, async/await, and concurrent execution
  • Advanced Topics: Type hints, metaclasses, descriptors, and the GIL

Why This Matters

Python is the most popular language for data science, machine learning, web development, and automation. Its readability and extensive standard library make it ideal for rapid development, while its type system and async capabilities support large-scale production applications. Understanding Python’s object model, memory management, and concurrency limitations is essential for writing efficient, maintainable code.

Common Mistakes

Assuming Python is slow because it is interpreted: CPython is slower than C for raw loops, but NumPy, Pandas, and other libraries use C extensions for hot paths. Profile before optimising — the bottleneck is in most cases not where you think.

Overusing global variables: Global variables create implicit coupling between functions. They make testing harder and introduce race conditions in concurrent code. Prefer function parameters and return values for data flow.

Ignoring virtual environments: System-wide package installation causes version conflicts between projects. Always use venv or conda to isolate project dependencies. This prevents “it works on my machine” problems.

Cross-References

  • Site Home: Main landing page for python notes.
  • Practice: Practice problems for revision.