Skip to content

Python Flashcards: Fundamentals

Python — Fundamentals Flashcards

20 interactive flashcards covering core Python concepts from types and control flow to metaclasses and the GIL. Press Space to flip, rate 1-4.


Intuition

Python is a dynamically typed, interpreted language where everything is an object — including functions, classes, and modules. List comprehensions provide concise syntax for creating lists from iterables, and generators yield values lazily (one at a time) instead of building entire lists in memory. The GIL (Global Interpreter Lock) ensures only one thread executes Python bytecode at a time, simplifying memory management but limiting CPU-bound parallelism.

Common Pitfalls

  • Mutable default arguments: Defining def f(x=[]) — the default list is shared across all calls, so mutations persist between calls. Use None as the default and create a new list inside the function.
  • Shallow vs deep copy: list.copy() creates a shallow copy — nested objects are still shared references. Use copy.deepcopy() for independent copies of nested structures.
  • Late binding closures: Closures in loops capture the variable by reference, not by value — the loop variable changes before the closure executes. Use a default argument to capture the current value.
  • GIL limitations: The Global Interpreter Lock prevents true parallelism for CPU-bound tasks in CPython. Use multiprocessing for CPU-bound work and asyncio for I/O-bound work.
  • Name mangling in classes: Double-underscore prefixes (__attr) trigger name mangling in classes, making attribute access different from single-underscore conventions. Use single underscores for “private” by convention.

Study Tips

  • Write list comprehensions for common patterns: Replace for loops with comprehensions for filtering and transforming data. This builds fluency with Pythonic idioms.
  • Use virtual environments for every project: Isolate dependencies with python -m venv .venv to prevent version conflicts between projects.
  • Read the Python data model: Understanding __init__, __repr__, __getitem__, and other dunder methods lets you make custom classes behave like built-in types.
  • Practise with the standard library: Write programs using collections, itertools, pathlib, and functools. The standard library is Python’s greatest strength.
  • Use type hints: Add type annotations to your functions and classes. Type hints improve code documentation and enable static analysis with mypy.
  • Practise with the GIL: Understand the Global Interpreter Lock by writing programs that compare threading vs multiprocessing for CPU-bound vs I/O-bound tasks. This builds intuition for Python’s concurrency model.
  • Use pdb for debugging: Python’s built-in debugger lets you step through code, inspect variables, and set breakpoints. Mastering pdb (or ipdb for improved output) is essential for debugging complex programs.

Cross-References

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

Detailed Content

This topic covers the fundamental principles and applications in depth. Each concept is explained with clear definitions, worked examples, and practice problems to reinforce understanding.

Core Concepts

Understanding these core concepts is essential for mastering this topic. They form the foundation for more advanced study and are frequently examined.

Worked Examples

Worked examples demonstrate how to apply the concepts to solve problems. Each example is broken down into clear steps with explanations.

Common Mistakes

  • Rushing through foundational material
  • Not practising problems after reading
  • Failing to connect concepts across topics

Further Reading

Consult the recommended textbooks and additional resources for deeper understanding of this topic.

Detailed Content

This topic covers the fundamental principles and applications in depth. Each concept is explained with clear definitions, worked examples, and practice problems to reinforce understanding.

Core Concepts

Understanding these core concepts is essential for mastering this topic. They form the foundation for more advanced study and are frequently examined.

Worked Examples

Worked examples demonstrate how to apply the concepts to solve problems. Each example is broken down into clear steps with explanations.

Common Mistakes

  • Rushing through foundational material
  • Not practising problems after reading
  • Failing to connect concepts across topics

Further Reading

Consult the recommended textbooks and additional resources for deeper understanding of this topic.

Detailed Content

This topic covers the fundamental principles and applications in depth. Each concept is explained with clear definitions, worked examples, and practice problems to reinforce understanding.

Core Concepts

Understanding these core concepts is essential for mastering this topic. They form the foundation for more advanced study and are frequently examined.

Worked Examples

Worked examples demonstrate how to apply the concepts to solve problems. Each example is broken down into clear steps with explanations.

Common Mistakes

  • Rushing through foundational material
  • Not practising problems after reading
  • Failing to connect concepts across topics

Further Reading

Consult the recommended textbooks and additional resources for deeper understanding of this topic.

Detailed Content

This topic covers the fundamental principles and applications in depth. Each concept is explained with clear definitions, worked examples, and practice problems to reinforce understanding.

Core Concepts

Understanding these core concepts is essential for mastering this topic. They form the foundation for more advanced study and are frequently examined.

Worked Examples

Worked examples demonstrate how to apply the concepts to solve problems. Each example is broken down into clear steps with explanations.

Common Mistakes

  • Rushing through foundational material
  • Not practising problems after reading
  • Failing to connect concepts across topics

Further Reading

Consult the recommended textbooks and additional resources for deeper understanding of this topic.

Detailed Content

This topic covers the fundamental principles and applications in depth. Each concept is explained with clear definitions, worked examples, and practice problems to reinforce understanding.

Core Concepts

Understanding these core concepts is essential for mastering this topic. They form the foundation for more advanced study and are frequently examined.

Worked Examples

Worked examples demonstrate how to apply the concepts to solve problems. Each example is broken down into clear steps with explanations.

Common Mistakes

  • Rushing through foundational material
  • Not practising problems after reading
  • Failing to connect concepts across topics

Further Reading

Consult the recommended textbooks and additional resources for deeper understanding of this topic.