🇮🇳 Data Science & Machine Learning · subject

Data Science & Machine Learning Python Programming for Data Science Syllabus

The Python Programming for Data Science syllabus for Data Science & Machine Learning in full: 4 chapters, 15 topics and 34 sub-topics, every one listed below, plus 60 Python Programming for Data Science flashcards with answers.

4Chapters
15Topics
34Sub-topics
60Flashcards

Python Programming for Data Science syllabus: all 4 chapters

Expand any chapter to see its topics and sub-topics.

  1. Python Fundamentals

    4 topics
    • Variables, Data Types and Operators
      • Numeric, string and boolean types
      • Type casting and dynamic typing
      • Arithmetic, comparison and logical operators
    • Control Flow
      • if-elif-else branching
      • for and while loops
      • break, continue and pass
    • Functions and Scope
      • Positional, keyword and default arguments
      • *args and **kwargs
      • Lambda and anonymous functions
      • Local vs global scope
    • Input, Output and Formatting
      • f-strings and format method
      • Reading from console
  2. Data Structures in Python

    4 topics
    • Lists and List Comprehensions
      • Indexing and slicing
      • Nested comprehensions
    • Tuples and Sets
      • Immutability of tuples
      • Set operations and uniqueness
    • Dictionaries
      • Key-value access and methods
      • Dictionary comprehensions
    • Strings and Text Processing
      • String methods
      • Regular expressions basics
  3. Object-Oriented and Modular Programming

    4 topics
    • Classes and Objects
      • Attributes and methods
      • Constructors and self
    • Inheritance and Polymorphism
      • Method overriding
      • super() usage
    • Modules and Packages
      • import mechanisms
      • pip and virtual environments
    • Exception Handling
      • try-except-finally
      • Raising and custom exceptions
  4. File Handling and Environment

    3 topics
    • Working with Files
      • Reading and writing text files
      • CSV and JSON files
    • Jupyter and IDE Workflow
      • Jupyter notebooks and cells
      • Markdown and magic commands
    • Anaconda and Package Management
      • conda environments
      • Dependency management

Data Science & Machine Learning Python Programming for Data Science flashcards — 60 questions with answers

  1. In Python, what distinguishes a variable from the value it refers to?

    A variable is a name (reference) bound to an object in memory; the value is the object itself. Assignment binds the name to the object rather than copying the value.

  2. List the four built-in numeric/text immutable scalar types most used in Python.

    int, float, bool, and str. (bool is actually a subclass of int.)

  3. What is the difference between integer division (//) and true division (/) in Python 3?

    / always returns a float (true division); // performs floor division, returning the largest integer less than or equal to the result (type depends on operands).

  4. What does the modulo operator % compute, and what does ** do?

    % returns the remainder of division; ** raises a number to a power (exponentiation), e.g. 2 ** 3 == 8.

  5. How do you check the type of an object at runtime in Python?

    Use type(obj) to get its type, or isinstance(obj, SomeType) to test membership (isinstance respects inheritance).

  6. What is the difference between == and is in Python?

    == compares values for equality; is compares object identity (whether two references point to the same object in memory).

  7. Which values are considered 'falsy' in Python?

    None, False, zero of any numeric type (0, 0.0), and empty sequences/collections ('', [], (), {}, set()). Everything else is truthy.

  8. What is the syntax and purpose of a ternary conditional expression in Python?

    value_if_true if condition else value_if_false — a one-line conditional that returns one of two values based on the condition.

  9. What are the two main loop constructs in Python and when do you use each?

    for loops iterate over an iterable (known sequence/collection); while loops repeat as long as a condition remains true (unknown number of iterations).

  10. What do break, continue, and pass do in Python loops?

    break exits the nearest enclosing loop; continue skips to the next iteration; pass is a no-op placeholder that does nothing.

  11. What is the purpose of the else clause on a Python for/while loop?

    The else block runs only if the loop completes normally without hitting a break statement.

  12. How do you generate a sequence of numbers to loop over without building a full list?

    Use range(start, stop, step); it produces a lazy, memory-efficient range object (stop is exclusive).

  13. What does enumerate() provide when looping, and zip()?

    enumerate(iterable) yields (index, item) pairs; zip(a, b, ...) yields tuples pairing elements from multiple iterables in parallel, stopping at the shortest.

  14. How do you define a function in Python and return a value?

    Use def name(parameters): followed by an indented body; use return value to send a result back. Without return, the function returns None.

  15. Explain positional, keyword, default, *args, and **kwargs parameters.

    Positional args match by order; keyword args match by name; default args supply a fallback value; *args collects extra positional args into a tuple; **kwargs collects extra keyword args into a dict.

  16. What is the LEGB rule for variable scope resolution in Python?

    Python looks up names in order: Local, Enclosing (nested function), Global (module), Built-in. The first match is used.

  17. 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) scope.

  18. Why is using a mutable default argument (e.g. def f(x=[])) dangerous?

    The default is evaluated once at definition time and shared across all calls, so mutations persist between calls. Use None as the default and create the mutable object inside the function instead.

  19. What is a lambda function in Python?

    An anonymous, single-expression function defined with lambda args: expression. It implicitly returns the expression's value and is often used as a short callback (e.g. in sorted's key).

  20. What function reads keyboard input, and what type does it always return?

    input(prompt) reads a line from standard input and always returns a str; convert with int()/float() as needed.

Show the other 40 Python Programming for Data Science flashcards
  1. How do you print without a trailing newline or with a custom separator?

    Use print(..., end='') to suppress the newline, and print(a, b, sep=', ') to set the separator between arguments.

  2. What is an f-string and how do you format a number to 2 decimal places with it?

    An f-string is a formatted string literal prefixed with f, e.g. f'{value}'. To show 2 decimals: f'{value:.2f}'.

  3. Give the format-spec for padding an integer to width 5 with leading zeros, and for a thousands separator.

    Leading zeros: f'{n:05d}'. Thousands separator: f'{n:,}' (e.g. 1000000 -> '1,000,000').

  4. What is the difference between str() and repr()?

    str() gives a readable, user-facing string; repr() gives an unambiguous developer representation (ideally one that could recreate the object). print uses str; the interactive shell uses repr.

  5. How do you create a list and access its last element?

    Create with square brackets, e.g. lst = [1, 2, 3]. Access the last element with lst[-1] (negative indexing counts from the end).

  6. What is the difference between list.append() and list.extend()?

    append(x) adds x as a single element; extend(iterable) adds each element of the iterable individually to the list.

  7. How does Python list slicing lst[start:stop:step] behave?

    It returns a new list from index start (inclusive) to stop (exclusive) stepping by step. Omitting parts uses defaults; a negative step reverses (e.g. lst[::-1] reverses the list).

  8. Write the general form of a list comprehension with a condition.

    [expression for item in iterable if condition] — builds a list of expression evaluated over filtered items.

  9. How do you sort a list in place vs. produce a new sorted list?

    lst.sort() sorts in place and returns None; sorted(lst) returns a new sorted list. Both accept key= and reverse= arguments.

  10. What is the key difference between a list and a tuple?

    Lists are mutable (can be changed after creation); tuples are immutable (fixed once created). Tuples can be used as dict keys/set elements when their contents are hashable.

  11. How do you create a single-element tuple, and how does tuple unpacking work?

    Single-element tuple needs a trailing comma: (x,). Unpacking assigns elements to multiple names: a, b, c = (1, 2, 3); use *rest to capture remaining items.

  12. What is a set in Python and what are its two defining properties?

    A set is an unordered collection of unique, hashable elements. It eliminates duplicates and allows fast membership testing (O(1) average).

  13. Give the operators/methods for set union, intersection, and difference.

    Union: a | b or a.union(b); intersection: a & b or a.intersection(b); difference: a - b or a.difference(b).

  14. How do you create an empty set vs. an empty dict?

    Empty set: set() ({} creates an empty dict, not a set). Empty dict: {} or dict().

  15. What is a dictionary and what is required of its keys?

    A dict is a mapping of key-value pairs with fast key lookup. Keys must be hashable (typically immutable: strings, numbers, tuples); values can be any object.

  16. Compare d[key] vs d.get(key) for accessing a dictionary value.

    d[key] raises KeyError if the key is missing; d.get(key, default) returns default (None if unspecified) instead of raising.

  17. 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().

  18. 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}.

  19. 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.

  20. 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.

  21. 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.

  22. 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.

  23. 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.

  24. 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.

  25. 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.

  26. 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.

  27. 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).

  28. 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.

  29. 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.

  30. 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.

  31. 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.

  32. 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').

  33. 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.

  34. 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.

  35. 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).

  36. 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).

  37. 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).

  38. 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.

  39. 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).

  40. 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.

Data Science & Machine Learning Python Programming for Data Science FAQ

What is in the Data Science & Machine Learning Python Programming for Data Science syllabus?

Data Science & Machine Learning Python Programming for Data Science is split into 4 chapters: Python Fundamentals, Data Structures in Python, Object-Oriented and Modular Programming and File Handling and Environment. Together they contain 15 topics and 34 sub-topics.

How many chapters are in Data Science & Machine Learning Python Programming for Data Science?

4 chapters, containing 15 topics and 34 sub-topics. The largest chapter is Python Fundamentals, with 4 topics.

Are there flashcards for Data Science & Machine Learning Python Programming for Data Science?

Yes — a 60-card Python Programming for Data Science deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.