Title: Python Deep Dive — LearnCoachAssist

Q: What is Python?
A: A high-level, interpreted, dynamically typed programming language created by Guido van Rossum in 1991.

Q: What is PEP 8?
A: Python's official style guide.

Q: What is PEP 20?
A: The Zen of Python — guiding principles by Tim Peters.

Q: What is the difference between Python 2 and Python 3?
A: Python 3 is the actively maintained version; Python 2 reached end-of-life in 2020.

Q: What is CPython?
A: The reference implementation of Python, written in C.

Q: What is PyPy?
A: A faster Python implementation using JIT compilation.

Q: What is Jython?
A: A Python implementation running on the JVM.

Q: What is duck typing?
A: "If it walks like a duck..." — type is determined by behavior, not declaration.

Q: What is mutable vs immutable?
A: Mutable can be changed (list, dict); immutable cannot (tuple, str, int).

Q: What is the difference between list and tuple?
A: Lists are mutable; tuples are immutable and hashable.

Q: What is a dictionary?
A: A mutable mapping of unique keys to values.

Q: What is a set?
A: An unordered collection of unique, hashable elements.

Q: What is a frozenset?
A: An immutable, hashable set.

Q: What is None?
A: Python's null value; the only instance of NoneType.

Q: What is the difference between == and is?
A: == checks value equality; is checks identity (same object).

Q: What is the GIL?
A: Global Interpreter Lock — only one thread executes Python bytecode at a time in CPython.

Q: Why does GIL matter?
A: It limits CPU-bound multithreading parallelism but allows simpler memory management.

Q: What is the difference between threading and multiprocessing?
A: Threading shares memory and is limited by GIL; multiprocessing uses separate processes for true parallelism.

Q: What is asyncio?
A: Python's library for asynchronous, single-threaded concurrency using coroutines.

Q: What is a coroutine?
A: A function defined with async def that can be paused at await points.

Q: What is await?
A: Yields control until an awaitable completes.

Q: What is an event loop?
A: The runtime that schedules and runs coroutines in asyncio.

Q: What is a list comprehension?
A: A concise syntax for creating lists, e.g., [x*2 for x in range(10)].

Q: What is a generator expression?
A: Like a list comprehension but lazy: (x*2 for x in range(10)).

Q: What is a generator function?
A: A function that yields values one at a time using `yield`.

Q: What is yield?
A: Returns a value while suspending the function's state.

Q: What is yield from?
A: Delegates iteration to another iterable or generator.

Q: What is an iterator?
A: An object with __iter__ and __next__ methods.

Q: What is an iterable?
A: An object that can return an iterator via __iter__.

Q: What is StopIteration?
A: Exception raised when an iterator is exhausted.

Q: What is a context manager?
A: An object supporting `with` via __enter__ and __exit__.

Q: What is the with statement used for?
A: Resource management (e.g., closing files automatically).

Q: What is contextlib?
A: A standard library module for context manager utilities.

Q: What is @contextmanager?
A: A decorator turning a generator into a context manager.

Q: What is a decorator?
A: A function that wraps another function, modifying its behavior.

Q: What is the @ syntax for decorators?
A: Syntactic sugar: @decorator above def is equivalent to f = decorator(f).

Q: What is functools.wraps?
A: Preserves the original function's metadata when decorating.

Q: What is *args?
A: Captures positional arguments as a tuple.

Q: What is **kwargs?
A: Captures keyword arguments as a dict.

Q: What is unpacking with * and **?
A: Spreads iterables/dicts when calling a function.

Q: What is positional-only parameter?
A: Parameters before / can only be passed positionally.

Q: What is keyword-only parameter?
A: Parameters after * can only be passed by keyword.

Q: What is type hinting?
A: Optional annotations specifying expected types (PEP 484).

Q: What is typing module?
A: Provides generic types like List, Dict, Optional, Union, Callable.

Q: What is mypy?
A: A static type checker for Python.

Q: What is dataclass?
A: A class decorator generating boilerplate like __init__, __repr__ from annotations.

Q: What is __slots__?
A: A class attribute restricting which instance attributes can be set; saves memory.

Q: What is the difference between class and instance attributes?
A: Class attributes are shared; instance attributes are per-instance.

Q: What is __init__?
A: Constructor method called when an instance is created.

Q: What is __new__?
A: Method that creates and returns a new instance (before __init__).

Q: What is __repr__?
A: Returns an unambiguous string representation, useful for debugging.

Q: What is __str__?
A: Returns a human-readable string representation.

Q: What is the difference between __repr__ and __str__?
A: __repr__ is for developers; __str__ is for users.

Q: What is __eq__?
A: Defines equality comparison.

Q: What is __hash__?
A: Returns hash value; required for use in sets/dicts as keys.

Q: What is __call__?
A: Makes an instance callable like a function.

Q: What is __getattr__?
A: Called when an attribute isn't found normally.

Q: What is __getattribute__?
A: Called for every attribute access; powerful but dangerous.

Q: What is __setattr__?
A: Called when setting an attribute.

Q: What is __getitem__?
A: Implements obj[key] indexing.

Q: What is __iter__?
A: Returns an iterator for the object.

Q: What is __enter__ / __exit__?
A: Context manager protocol methods.

Q: What is multiple inheritance?
A: A class can inherit from multiple parents.

Q: What is the MRO?
A: Method Resolution Order — the order Python searches base classes (C3 linearization).

Q: What is super()?
A: Returns a proxy for calling the parent class's methods.

Q: What is metaclass?
A: A class whose instances are classes; controls class creation.

Q: What is type()?
A: Built-in returning an object's type; also used to create classes dynamically.

Q: What is isinstance()?
A: Checks if object is instance of a class (or subclass).

Q: What is issubclass()?
A: Checks if a class is a subclass of another.

Q: What is abstract base class (ABC)?
A: A class that cannot be instantiated and may declare abstract methods.

Q: What is @abstractmethod?
A: Decorator marking a method abstract; subclasses must implement it.

Q: What is Protocol (typing)?
A: Structural subtyping — class qualifies by having required methods.

Q: What is duck typing in PEP 544?
A: Codified via Protocol classes.

Q: What is descriptor protocol?
A: Objects with __get__/__set__/__delete__ control attribute access.

Q: What is @property?
A: A descriptor making a method accessible like an attribute.

Q: What is @cached_property?
A: Computes a property once and caches it on the instance.

Q: What is closure?
A: A function that captures variables from its enclosing scope.

Q: What is the LEGB rule?
A: Scope lookup order: Local, Enclosing, Global, Built-in.

Q: What is global keyword?
A: Declares a variable refers to module-level scope.

Q: What is nonlocal keyword?
A: Refers to nearest enclosing (non-global) scope.

Q: What is the difference between shallow and deep copy?
A: Shallow copies references; deep copy recursively duplicates objects.

Q: What is copy.copy()?
A: Performs a shallow copy.

Q: What is copy.deepcopy()?
A: Performs a deep copy.

Q: What is the difference between mutable default argument issue?
A: def f(x=[]) — the list is shared across calls; use None as default instead.

Q: What is PEP 572 (walrus operator)?
A: := assigns a value inside an expression.

Q: What is f-string?
A: Formatted string literals (PEP 498): f"value={x}".

Q: What is the str.format() method?
A: Older formatting using "{} {}".format(a, b).

Q: What is % formatting?
A: Oldest style: "%s %d" % (a, b).

Q: What is the bytes type?
A: Immutable sequence of bytes.

Q: What is bytearray?
A: Mutable sequence of bytes.

Q: What is string encoding?
A: Converting str to bytes using e.g. utf-8.

Q: What is the difference between ASCII and UTF-8?
A: ASCII is 7-bit; UTF-8 is variable-width Unicode encoding.

Q: What is the GIL's effect on CPU-bound code?
A: Limits parallelism; use multiprocessing or native extensions.

Q: What is concurrent.futures?
A: High-level API for asynchronous execution (ThreadPoolExecutor, ProcessPoolExecutor).

Q: What is os.fork()?
A: Creates a child process (Unix only); generally use multiprocessing.

Q: What is subprocess?
A: Module for spawning external processes.

Q: What is pathlib?
A: Object-oriented filesystem paths.

Q: What is os.path vs pathlib.Path?
A: os.path is string-based; pathlib is object-oriented and modern.

Q: What is venv?
A: Module for creating lightweight virtual environments.

Q: What is pip?
A: Python's package installer.

Q: What is requirements.txt?
A: A file listing package dependencies.

Q: What is pip freeze?
A: Outputs installed packages and versions.

Q: What is setup.py?
A: Legacy build script for Python packages.

Q: What is pyproject.toml?
A: Modern (PEP 518/621) project configuration.

Q: What is wheel?
A: A built-package format (.whl) for fast installation.

Q: What is sdist?
A: A source distribution format.

Q: What is PyPI?
A: Python Package Index — official package repository.

Q: What is Poetry?
A: A modern dependency management and packaging tool.

Q: What is Pipenv?
A: Combines pip and virtualenv with a Pipfile.

Q: What is conda?
A: A package and environment manager (popular in data science).

Q: What is virtualenv?
A: A tool for isolated Python environments (precursor to venv).

Q: What is the importance of __init__.py?
A: Marks a directory as a Python package (less strict in Python 3.3+).

Q: What is a namespace package?
A: A package split across multiple locations without __init__.py.

Q: What is __main__.py?
A: Entry point when a package is run with python -m pkg.

Q: What is if __name__ == "__main__":?
A: Guards code so it only runs when the script is executed directly.

Q: What is __all__?
A: A module attribute defining what names `from module import *` exports.

Q: What is logging module?
A: Standard library for structured logging.

Q: What is the difference between print and logging?
A: print() writes to stdout; logging is configurable with levels, handlers, formats.

Q: What are logging levels?
A: DEBUG, INFO, WARNING, ERROR, CRITICAL.

Q: What is a logging handler?
A: Determines where log records go (file, console, network).

Q: What is a logging formatter?
A: Specifies the layout of log records.

Q: What is logging.config.dictConfig?
A: Configures logging from a dictionary.

Q: What is exception?
A: An error condition; instances of BaseException.

Q: What is try/except?
A: Block for handling exceptions.

Q: What is the difference between Exception and BaseException?
A: BaseException is the root; Exception is the parent of most user-facing exceptions.

Q: What is else in try/except?
A: Runs only if no exception was raised.

Q: What is finally?
A: Runs whether or not an exception occurred.

Q: What is raise?
A: Throws an exception.

Q: What is exception chaining (raise from)?
A: Indicates an exception was triggered by another.

Q: What is a custom exception?
A: A class inheriting from Exception or a subclass.

Q: What is logging.exception()?
A: Logs an ERROR with exception traceback.

Q: What is unittest?
A: Python's built-in testing framework (xUnit style).

Q: What is pytest?
A: A popular third-party testing framework with fixtures and concise syntax.

Q: What is a fixture (pytest)?
A: Reusable setup/teardown for tests.

Q: What is monkeypatching?
A: Dynamically modifying code at runtime, often for tests.

Q: What is mock?
A: A library for replacing parts of code with mock objects during testing.

Q: What is unittest.mock.patch?
A: Context manager/decorator that replaces an object during a test.

Q: What is doctest?
A: Tests embedded in docstrings.

Q: What is the difference between unit, integration, end-to-end tests?
A: Unit tests isolate; integration combines; e2e exercises the full system.

Q: What is test-driven development (TDD)?
A: Writing tests before implementation.

Q: What is parametrize (pytest)?
A: Decorator running tests with multiple input sets.

Q: What is coverage.py?
A: A tool measuring code coverage of tests.

Q: What is tox?
A: Manages virtual environments for testing across versions.

Q: What is hypothesis?
A: Property-based testing library.

Q: What is REPL?
A: Read-Eval-Print Loop — Python's interactive prompt.

Q: What is IPython?
A: Enhanced interactive Python shell.

Q: What is Jupyter Notebook?
A: A web app combining code, output, and narrative.

Q: What is the difference between %timeit and timeit module?
A: %timeit is an IPython magic; timeit is a stdlib module.

Q: What is profiling?
A: Measuring code performance to find bottlenecks.

Q: What is cProfile?
A: Built-in profiler.

Q: What is line_profiler?
A: Third-party tool profiling line-by-line.

Q: What is memory_profiler?
A: Tool for line-by-line memory profiling.

Q: What is PEP 657?
A: Better tracebacks pointing to specific expressions.

Q: What is the standard library?
A: Modules shipped with Python (os, sys, math, collections, etc.).

Q: What is collections.namedtuple?
A: A factory for tuple subclasses with named fields.

Q: What is collections.OrderedDict?
A: A dict maintaining insertion order (Python 3.7+ regular dicts also do).

Q: What is collections.defaultdict?
A: A dict with default values for missing keys.

Q: What is collections.Counter?
A: A dict subclass for counting hashable objects.

Q: What is collections.deque?
A: A double-ended queue for fast appends/pops at both ends.

Q: What is collections.ChainMap?
A: A class linking multiple dicts as a single mapping.

Q: What is itertools?
A: Iterator building blocks like chain, cycle, combinations.

Q: What is functools.lru_cache?
A: Memoizes function results.

Q: What is functools.partial?
A: Creates a function with some arguments pre-filled.

Q: What is functools.reduce?
A: Applies a function cumulatively to a sequence.

Q: What is operator module?
A: Functional versions of operators (e.g., operator.add).

Q: What is heapq?
A: A heap (priority queue) implementation.

Q: What is bisect?
A: Binary search on sorted lists.

Q: What is json module?
A: Encoding and decoding JSON.

Q: What is pickle?
A: Python-specific binary serialization.

Q: What is the difference between pickle and JSON?
A: JSON is interoperable; pickle handles arbitrary Python objects but is Python-only and insecure with untrusted data.

Q: What is csv module?
A: Reading and writing CSV files.

Q: What is sqlite3?
A: Built-in SQLite database driver.

Q: What is requests?
A: A popular HTTP library.

Q: What is urllib?
A: The standard library HTTP module.

Q: What is socket module?
A: Low-level networking interface.

Q: What is asyncio.run()?
A: Top-level entry to run async coroutines.

Q: What is asyncio.gather()?
A: Runs multiple awaitables concurrently and collects results.

Q: What is asyncio.create_task()?
A: Schedules a coroutine as a Task.

Q: What is asyncio.Queue?
A: An async-safe queue for producer/consumer patterns.

Q: What is aiohttp?
A: Asynchronous HTTP client/server.

Q: What is FastAPI?
A: A modern web framework using type hints, async, and OpenAPI.

Q: What is Flask?
A: A lightweight, micro web framework.

Q: What is Django?
A: A full-featured web framework with ORM, admin, and batteries.

Q: What is the difference between FastAPI and Flask?
A: FastAPI is async, type-hinted, and auto-documented; Flask is simpler and synchronous by default.

Q: What is WSGI?
A: Web Server Gateway Interface — synchronous Python web server standard.

Q: What is ASGI?
A: Asynchronous Server Gateway Interface — async successor to WSGI.

Q: What is gunicorn?
A: A WSGI HTTP server commonly used in production.

Q: What is uvicorn?
A: An ASGI server for async frameworks.

Q: What is __version__?
A: Conventional module attribute for version info.

Q: What is semantic versioning?
A: Major.Minor.Patch scheme indicating compatibility.

Q: What is the importance of docstrings?
A: In-code documentation accessed via help() and tools.

Q: What is Sphinx?
A: A documentation generator for Python.

Q: What is reStructuredText?
A: A markup language used by Sphinx.

Q: What is type alias?
A: A name for a type, e.g., UserID = int.

Q: What is TypeVar?
A: Defines a type variable for generic functions.

Q: What is Generic class?
A: A class parameterized by type variables.

Q: What is Optional[X]?
A: Equivalent to Union[X, None].

Q: What is Union (typing)?
A: A type that is one of several types.

Q: What is Literal type?
A: Restricts a value to specific literals (PEP 586).

Q: What is TypedDict?
A: Dict with fixed string keys and known value types (PEP 589).

Q: What is dataclass(frozen=True)?
A: Makes the instance immutable.

Q: What is dataclass(slots=True)?
A: Generates __slots__ for memory efficiency.

Q: What is __post_init__?
A: Method run after dataclass __init__.

Q: What is functools.cache?
A: Memoization without size limit.

Q: What is __init_subclass__?
A: Hook called when a subclass is created.

Q: What is __set_name__?
A: Descriptor hook to learn the attribute name.

Q: What is f-string debug mode?
A: f"{x=}" prints "x=value" (Python 3.8+).

Q: What is structural pattern matching?
A: The match/case statement (PEP 634, Python 3.10+).

Q: What is walrus in comprehension?
A: Reusing a computed value via :=.

Q: What is the difference between == and = in match?
A: match uses pattern matching syntax, not equality.

Q: What is exception group (3.11+)?
A: Multiple unrelated exceptions raised together.

Q: What is task groups (3.11+)?
A: Structured concurrency for asyncio.

Q: What is tomllib (3.11+)?
A: Reading TOML files in the standard library.

Q: What is the role of asyncio.timeout()?
A: Raises timeout error after specified seconds.

Q: What is the difference between thread-safe and async-safe?
A: Threads vs coroutines have different safety considerations.

Q: What is GIL alternatives in 3.12+?
A: Per-interpreter GIL (PEP 684) and sub-interpreters.

Q: What is Python's reference counting?
A: Memory management based on tracking references.

Q: What is garbage collection in Python?
A: Reference counting + cyclic GC for circular references.

Q: What is sys.getrefcount?
A: Returns reference count of an object.

Q: What is __del__?
A: Destructor; called when object is about to be destroyed.

Q: What is weakref?
A: A reference that doesn't prevent garbage collection.

Q: What is the difference between list.append() and list.extend()?
A: append adds one item; extend concatenates an iterable.

Q: What is the difference between sorted() and list.sort()?
A: sorted returns a new list; list.sort sorts in place.

Q: What is the key parameter in sort?
A: A function returning a sort key.

Q: What is reverse=True?
A: Sorts in descending order.

Q: What is dict comprehension?
A: {k: v for k, v in iterable}.

Q: What is set comprehension?
A: {x for x in iterable}.

Q: What is the unpacking operator in function calls?
A: * unpacks iterables, ** unpacks dicts.

Q: What is enumerate()?
A: Yields (index, value) pairs.

Q: What is zip()?
A: Combines multiple iterables element-wise.

Q: What is the difference between zip and zip_longest?
A: zip stops at shortest; zip_longest pads with fillvalue.

Q: What is range()?
A: Returns an iterable over a sequence of integers.

Q: What is map()?
A: Applies a function to each item in an iterable.

Q: What is filter()?
A: Keeps items where a function returns True.

Q: What is the difference between list(map(...)) and a comprehension?
A: Comprehensions are often more Pythonic and readable.

Q: What is any() / all()?
A: Boolean reductions: True if any/all elements are truthy.

Q: What is sum(), min(), max()?
A: Aggregate reductions over iterables.

Q: What is divmod()?
A: Returns (quotient, remainder) of division.

Q: What is abs()?
A: Absolute value.

Q: What is round()?
A: Rounds a number; banker's rounding by default.

Q: What is the math module?
A: Mathematical functions and constants.

Q: What is the decimal module?
A: Arbitrary precision decimal arithmetic.

Q: What is the fractions module?
A: Rational number arithmetic.

Q: What is random module?
A: Pseudo-random number generation.

Q: What is secrets module?
A: Cryptographically secure random for secrets.

Q: What is hashlib?
A: Cryptographic hashes (md5, sha1, sha256, etc.).

Q: What is base64 module?
A: Base64 encoding and decoding.

Q: What is the role of `__all__`?
A: Defines explicit public API of a module.

Q: What is the typing.Final?
A: Marks a name as final (can't be reassigned).

Q: What is duck-typed protocol vs nominal typing?
A: Protocols check structure; nominal checks declared inheritance.

Q: What is the difference between class method and static method?
A: @classmethod receives cls; @staticmethod receives nothing.

Q: What is a closure variable assignment trap?
A: Modifying enclosing variables requires nonlocal.

Q: What is the difference between import and from ... import?
A: import preserves namespace; from imports specific names.

Q: What is relative import?
A: Importing using . or .. from within a package.

Q: What is circular import?
A: When modules import each other, often causing errors.

Q: What is sys.path?
A: List of directories Python searches for modules.

Q: What is PYTHONPATH?
A: Environment variable extending sys.path.

Q: What is the difference between is None and == None?
A: Use `is None` — it's faster and idiomatic.

Q: What is truthy/falsy?
A: Values evaluated in boolean contexts; empty containers, 0, None are falsy.

Q: What is short-circuit evaluation?
A: Boolean operators stop evaluating once result is determined.

Q: What is the difference between `not x` and `x is None`?
A: `not x` is true for any falsy value; `is None` checks specifically for None.

Q: What is "ask forgiveness, not permission" (EAFP)?
A: Pythonic style: try the operation, handle exceptions, rather than checking first.

Q: What is "look before you leap" (LBYL)?
A: Checking conditions before acting; less Pythonic.