🌍 Python · flashcards

Python Python Programming Flashcards

63 question-and-answer cards covering Python Programming as it is examined in Python. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

63Cards in deck
24Free preview
37Syllabus topics
~151Chars per answer
FreePrice

24 sample cards from the Python Programming deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What is a Python docstring and how do you access it?

    A docstring is a string literal as the first statement in a function, class, or module, used for documentation. Access it via the object's __doc__ attribute or help(object).

  2. Explain variable scope in Python and the LEGB rule.

    LEGB defines name lookup order: Local, Enclosing (nested function), Global (module), Built-in. Python searches these scopes in that order to resolve a name.

  3. What do the global and nonlocal keywords do?

    global lets a function rebind a module-level variable. nonlocal lets a nested function rebind a variable in the nearest enclosing (non-global) function scope.

  4. What is a decorator in Python?

    A decorator is a function that takes another function and extends/modifies its behavior without changing its code, applied with @decorator_name syntax above a function definition.

  5. What is the Python Standard Library?

    A large collection of modules and packages bundled with Python (e.g., math, os, sys, random, datetime, json) providing common functionality without separate installation ('batteries included').

  6. Which standard library module provides mathematical functions, and what does math.sqrt(16) return?

    The math module. math.sqrt(16) returns $4.0$ (a float).

  7. What is a Python module, and how do you create one?

    A module is a single .py file containing Python definitions and statements. You create one simply by saving code in a file (e.g., mymodule.py) and importing it with import mymodule.

  8. What are three ways to import from a module?

    1) import module (then module.name). 2) from module import name (direct access to name). 3) import module as alias (e.g., import numpy as np).

  9. What is the purpose of the if __name__ == '__main__': block?

    It contains code that runs only when the file is executed directly as a script, not when it is imported as a module (because __name__ equals '__main__' only for the directly-run file).

  10. What is a Python package, and what file traditionally marks a directory as one?

    A package is a directory containing multiple modules, organizing them into a namespace hierarchy. An __init__.py file traditionally marks a directory as a package.

  11. What is the standard built-in function to open a file, and what is the recommended way to ensure it closes?

    open(filename, mode) opens a file. Use a with statement (context manager): with open('f.txt') as file: — it automatically closes the file even if an error occurs.

  12. What file modes are used for reading, writing (overwrite), and appending?

    'r' = read (default), 'w' = write (creates/truncates/overwrites), 'a' = append (adds to end). Add 'b' for binary (e.g., 'rb') and '+' for read-and-write.

  13. What is the difference between file.read(), file.readline(), and file.readlines()?

    read() returns the entire file as one string; readline() returns the next single line; readlines() returns a list of all lines.

  14. How do you write text to a file, and does write() add a newline automatically?

    Use file.write(text) (or file.writelines(list)). write() does NOT add a newline automatically — you must include \n yourself.

  15. Why is the os.path / pathlib approach preferred over hardcoding file paths with slashes?

    They build OS-independent paths. os.path.join() and pathlib.Path use the correct separator for each operating system (/ on Unix, \\ on Windows), avoiding cross-platform bugs.

  16. What modern module/class provides object-oriented file path handling, and how do you join paths with it?

    The pathlib module's Path class. Join paths with the / operator: Path('folder') / 'file.txt'.

  17. What is an exception in Python?

    An exception is an error detected during execution that disrupts the normal flow of the program. If unhandled, it propagates up and terminates the program with a traceback.

  18. What is the difference between a syntax error and an exception?

    A syntax error occurs at parse time before the program runs (invalid code structure). An exception occurs at runtime during execution of otherwise syntactically valid code.

  19. Name common built-in exceptions for: wrong type, bad value, missing dict key, and division by zero.

    TypeError (wrong type), ValueError (right type but invalid value), KeyError (missing dictionary key), and ZeroDivisionError (dividing by zero).

  20. What is the basic try/except syntax for handling an exception?

    try:\n risky_code()\nexcept SomeError as e:\n handle(e)\nThe except block runs only if a matching exception is raised in the try block.

  21. What is the purpose of the else and finally clauses in a try statement?

    else runs only if the try block raised no exception. finally always runs (whether or not an exception occurred), typically for cleanup like closing resources.

  22. How do you manually trigger an exception in Python?

    Use the raise statement, e.g., raise ValueError('invalid input'). You can raise built-in or custom exceptions.

  23. How do you create a custom exception class in Python?

    Define a class that inherits from Exception (or a subclass): class MyError(Exception): pass. Then raise it with raise MyError('message').

  24. How can you catch multiple different exception types in Python?

    Use multiple except blocks, or group types in a tuple: except (TypeError, ValueError) as e:. Order matters — more specific exceptions should come before general ones.

What this deck covers

The Python Programming deck follows the Python Python Programming syllabus — 12 chapters and 37 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 5.3 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 151 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Python Programming flashcards FAQ

How many Python Programming flashcards are in this Python deck?

63 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these Python flashcards free?

Yes. The preview here is free to read with no signup, and the full 63-card deck is free inside the Examius app.

What do the Python Programming cards cover?

They follow the Python Python Programming syllabus — 12 chapters and 37 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.