IBM Data Science Professional Certificate study materials
IBM Data Science Professional Certificate study resources

IBM Data Science Professional Certificate: Python for Data Science and Programming Fundamentals

IBM Data Science Professional Certificate · Work through your exam, one topic at a time.

All guide sections

Python for Data Science and Programming Fundamentals

Python for Data Science and Programming Fundamentals

This domain tests practical Python: data types, containers, control flow, functions, classes, exceptions, file handling, and the idioms used in notebooks. Questions often ask you to predict output or choose the safer construct.

Core rules

  • Lists, dictionaries, and sets are mutable; strings and tuples are immutable.
  • Indexing is zero-based; slicing excludes the stop index.
  • == compares values; is compares object identity.
  • Default arguments are evaluated once, so avoid mutable defaults such as def f(items=[]).
  • Use try/except/else/finally and raise specific exceptions.
  • Open files with with open(...) as f so they close reliably.
  • Follow PEP 8: snake_case for functions and variables, CapWords for classes.

Worked example

Count the most common words in a file:

from collections import Counter

def top_words(path, n=3):
    with open(path, encoding='utf-8') as f:
        words = f.read().lower().split()
    return Counter(words).most_common(n)

Reasoning: with guarantees closure; lower() normalizes case; split() tokenizes on whitespace; Counter counts without a manual dictionary loop; most_common returns tuples sorted by descending frequency. If punctuation must be removed, preprocess before counting rather than changing the return type.

Traps

  • Mutating a list while iterating over it.
  • Assigning the result of list.append, which is None.
  • Forgetting self in instance methods.
  • Catching broad Exception and hiding real bugs.
  • Assuming range(1, 5) includes 5; it yields 1 through 4.
  • Mixing class attributes and instance attributes.