🌍 Data Science · flashcards

Data Science Python Programming Flashcards

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

73Cards in deck
24Free preview
30Syllabus topics
~121Chars 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. How do you compute $\sqrt{16}$ and access $\pi$ using the standard library?

    Import the math module: math.sqrt(16) returns $4.0$, and math.pi returns approximately $3.14159$.

  2. What is the difference between import module and from module import name?

    import module brings in the whole module (access via module.name); from module import name brings a specific object directly into the namespace.

  3. What is a Python module?

    A single .py file containing Python definitions and statements that can be imported and reused in other programs.

  4. What does the if __name__ == '__main__': idiom do in a module?

    It runs the indented code only when the file is executed directly, not when it is imported as a module.

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

    A package is a directory of related modules; an __init__.py file traditionally marks the directory as a package (optional since Python 3.3 namespace packages).

  6. What is the difference between an absolute import and a relative import?

    An absolute import uses the full path from the project root (import mypackage.module); a relative import uses dots relative to the current package (from . import module).

  7. What is the recommended way to open a file so it closes automatically?

    Use a with statement (context manager): with open('file.txt') as f: — the file is closed automatically when the block ends.

  8. What are the file modes 'r', 'w', 'a', and 'r+'?

    'r' read (default), 'w' write (truncates/creates), 'a' append (adds to end), and 'r+' read and write.

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

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

  10. What is the difference between text mode and binary mode when opening a file?

    Text mode ('t', default) reads/writes str and handles encoding; binary mode ('b', e.g., 'rb') reads/writes raw bytes without decoding.

  11. What methods write data to a file in Python?

    f.write(string) writes a single string, and f.writelines(list) writes a list of strings; neither adds newline characters automatically.

  12. Why might you call f.flush() when writing to a file?

    To force buffered data to be written to disk immediately, rather than waiting for the buffer to fill or the file to close.

  13. Which standard library module is the modern, object-oriented way to handle file paths?

    pathlib, whose Path class provides cross-platform path manipulation (e.g., Path('data') / 'file.txt').

  14. What does os.path.join('folder', 'file.txt') do and why use it?

    It joins path components with the correct OS-specific separator, ensuring code works across Windows and Unix systems.

  15. How do you check whether a file or directory exists using the standard library?

    Use os.path.exists(path) or, with pathlib, Path(path).exists().

  16. What is the difference between an absolute path and a relative path?

    An absolute path specifies the location from the root of the filesystem; a relative path is specified relative to the current working directory.

  17. What is an exception in Python?

    An error detected during execution that disrupts the normal flow of the program; if unhandled, it terminates the program with a traceback.

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

    A syntax error is detected before execution when the code cannot be parsed; an exception (runtime error) occurs while the program is running.

  19. What is the base class of (almost) all built-in exceptions in Python?

    BaseException, though user-defined and most catchable exceptions inherit from Exception.

  20. Name three common built-in exception types and when they occur.

    ValueError (right type, wrong value), TypeError (wrong type), and ZeroDivisionError (division by zero). Others include KeyError, IndexError, and FileNotFoundError.

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

    try:\n risky_code()\nexcept SomeError:\n handle_it() — code in try is attempted, and except catches the named error.

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

    else runs if no exception occurred in the try block; finally always runs (cleanup), whether or not an exception was raised.

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

    Use the raise statement, e.g., raise ValueError('invalid input').

  24. How can you catch an exception and access its error message in the except block?

    Use as to bind it, e.g., except ValueError as e:, then use str(e) or print(e) to read the message.

What this deck covers

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

Answers are written to be recallable, not just readable — averaging about 121 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 Data Science deck?

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

Are these Data Science flashcards free?

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

What do the Python Programming cards cover?

They follow the Data Science Python Programming syllabus — 9 chapters and 30 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.