🇮🇳 Data Science & Machine Learning · flashcards
Data Science & Machine Learning Python Programming for Data Science Flashcards
60 question-and-answer cards covering Python Programming for Data Science as it is examined in Data Science & Machine Learning. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.
24 sample cards from the Python Programming for Data Science deck
Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.
How do you iterate over a dictionary's keys, values, and key-value pairs?
Use for k in d (or d.keys()), for v in d.values(), and for k, v in d.items().
Write a dict comprehension that maps numbers 0-4 to their squares.
{n: n**2 for n in range(5)} -> {0:0, 1:1, 2:4, 3:9, 4:16}.
What does d.setdefault(key, default) do?
Returns d[key] if the key exists; otherwise inserts key with the given default and returns that default. Useful for grouping/accumulating.
Are Python strings mutable, and what does a string 'method' like upper() return?
Strings are immutable. Methods like upper() do not modify the original; they return a new string with the change.
How do split() and join() work for strings?
text.split(sep) breaks a string into a list of substrings (default splits on whitespace); sep.join(list_of_strings) concatenates the list into one string using sep as the separator.
Name three common string methods for cleaning/searching text and what they do.
strip() removes leading/trailing whitespace; replace(old, new) substitutes substrings; find()/index() locate a substring (find returns -1 if absent, index raises). startswith()/endswith() test prefixes/suffixes.
What is the difference between defining a class with class Name: and creating an instance?
class Name: defines a blueprint (type); calling Name() creates an instance (object) of that class, invoking __init__ to initialize it.
What is the role of self and __init__ in a Python class?
self refers to the current instance and must be the first parameter of instance methods. __init__ is the constructor, run when an instance is created, used to set up instance attributes.
Distinguish an instance attribute from a class attribute.
An instance attribute (set via self.x) is unique per object; a class attribute is defined in the class body and shared by all instances unless overridden on an instance.
How do you create a subclass and call the parent class's method/constructor?
Define class Child(Parent): and use super().method() (e.g. super().__init__(...)) to invoke the parent's implementation.
What is polymorphism in Python and how is method overriding related?
Polymorphism lets different classes respond to the same method call in their own way. Overriding is redefining an inherited method in a subclass so the subclass's version is used for its instances (duck typing also enables polymorphism).
What is the difference between import module, import module as m, and from module import name?
import module brings in the module (access as module.name); import module as m gives it an alias; from module import name imports a specific object directly into the current namespace.
What file makes a directory a Python package, and what is its modern role?
__init__.py marks a directory as a package. Since Python 3.3, namespace packages can exist without it, but __init__.py is still used to run package initialization and control what's exported.
What is the purpose of the if __name__ == '__main__': guard?
It runs the enclosed code only when the file is executed directly, not when it is imported as a module—separating script behavior from reusable code.
What is the basic structure of try/except/else/finally for exception handling?
try runs risky code; except catches specified exceptions; else runs if no exception occurred; finally always runs (cleanup) whether or not an exception was raised.
How do you catch a specific exception, access its message, and re-raise or raise your own?
Use except SomeError as e: then e holds the exception (str(e) for its message). Re-raise with bare raise; raise your own with raise ValueError('msg').
Why is the with statement preferred for opening files?
with open(path) as f: creates a context manager that automatically closes the file (even on error), preventing resource leaks—no explicit f.close() needed.
What do the file modes 'r', 'w', 'a', and 'b' mean?
'r' read (default), 'w' write/truncate (creates/overwrites), 'a' append (writes to end), 'b' binary mode (combined like 'rb'). 'r+' allows read and write.
How do you read a file line by line efficiently vs. reading it all at once?
Iterate directly: for line in f: (memory-efficient, one line at a time). Read all at once with f.read() (whole file as a string) or f.readlines() (list of lines).
In Jupyter, what is the difference between a code cell and a markdown cell, and how do you run a cell?
A code cell executes Python and shows output; a markdown cell renders formatted text/notes. Run a cell with Shift+Enter (run and move to next) or Ctrl+Enter (run in place).
What are Jupyter line magics vs. cell magics, with one example of each?
Line magics start with % and affect one line (e.g. %timeit one_statement); cell magics start with %% and affect the whole cell (e.g. %%timeit for the entire cell).
What does conda do that pip does not, and what is a conda environment?
conda manages packages AND non-Python dependencies/binaries and can create isolated environments; pip installs only Python packages from PyPI. A conda environment is an isolated directory with its own Python and packages.
Give the conda commands to create a named environment with a specific Python version and to activate it.
Create: conda create -n myenv python=3.11. Activate: conda activate myenv (deactivate with conda deactivate).
How do you reproduce a conda environment from a file, and what file format is standard?
Export with conda env export > environment.yml; recreate with conda env create -f environment.yml. The standard format is a YAML file listing channels and dependencies.
What this deck covers
The Python Programming for Data Science deck follows the Data Science & Machine Learning Python Programming for Data Science syllabus — 4 chapters and 15 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 15.0 cards per chapter.
Answers are written to be recallable, not just readable — averaging about 157 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 for Data Science flashcards FAQ
How many Python Programming for Data Science flashcards are in this Data Science & Machine Learning deck?
60 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 & Machine Learning flashcards free?
Yes. The preview here is free to read with no signup, and the full 60-card deck is free inside the Examius app.
What do the Python Programming for Data Science cards cover?
They follow the Data Science & Machine Learning Python Programming for Data Science syllabus — 4 chapters and 15 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.