Python practice · 15 questions

Python for data engineers: practice set

15 questions on the Python a data engineer uses daily: functional tools, exceptions, classes for pipelines, NumPy and pandas. Every "what does this print" answer was checked by running the code with NumPy 2 and pandas 2. At the end you get a score per topic.

  1. Question 1 of 15 · Functional programmingWhat does this print?
    Python
    nums = [1, 2, 3]
    print(list(map(lambda x: x * 10, filter(lambda x: x > 1, nums))))
  2. Question 2 of 15 · Functional programmingWhat does this print?
    Python
    from functools import reduce
    print(reduce(lambda acc, x: acc * x, [1, 2, 3, 4]))
  3. Question 3 of 15 · Functional programmingWhat does this print?
    Python
    rows = [('b', 2), ('a', 3), ('c', 1)]
    print(sorted(rows, key=lambda r: r[1])[0], max(rows)[0])
  4. Question 4 of 15 · Modules & exceptionsWhy do scripts use if __name__ == "__main__":?
  5. Question 5 of 15 · Modules & exceptionsWhat does this print?
    Python
    class PipelineError(Exception):
        pass
    
    try:
        raise PipelineError('bad row 42')
    except Exception as e:
        print(type(e).__name__, e)
  6. Question 6 of 15 · Modules & exceptionsWhat does this print?
    Python
    try:
        x = 1
    except ValueError:
        print('error', end=' ')
    else:
        print('ok', end=' ')
    finally:
        print('done')
  7. Question 7 of 15 · OOP for pipelinesWhat happens when this runs?
    Python
    from abc import ABC, abstractmethod
    
    class Source(ABC):
        @abstractmethod
        def read(self): ...
    
    src = Source()
  8. Question 8 of 15 · OOP for pipelinesWhat happens when this runs?
    Python
    class Job:
        def __init__(self):
            self._status = 'new'
    
        @property
        def status(self):
            return self._status
    
    job = Job()
    job.status = 'done'
  9. Question 9 of 15 · NumPyWhat does this print?
    Python
    import numpy as np
    
    a = np.array([[1, 2], [3, 4]])
    print((a + np.array([10, 20])).tolist())
  10. Question 10 of 15 · NumPyWhat does this print?
    Python
    import numpy as np
    
    a = np.arange(5)
    b = a[1:3]
    b[0] = 99
    print(a.tolist())
  11. Question 11 of 15 · NumPyWhat does this print?
    Python
    import numpy as np
    
    x = np.array([1.0, np.nan])
    print(np.nan == np.nan, np.isnan(x).tolist())
  12. Question 12 of 15 · pandasWhat does this print?
    Python
    import pandas as pd
    
    print(pd.Series([1, None, 3]).mean())
  13. Question 13 of 15 · pandasWhat does this print?
    Python
    import pandas as pd
    
    df = pd.DataFrame({'k': ['a', 'b', 'a'], 'v': [1, 2, 3]})
    print(df.groupby('k')['v'].sum().to_dict())
  14. Question 14 of 15 · pandasWhat does this print?
    Python
    import pandas as pd
    
    orders = pd.DataFrame({'cust': [1, 1], 'amount': [100, 50]})
    emails = pd.DataFrame({'cust': [1, 1], 'email': ['a@x.com', 'a@y.com']})
    merged = orders.merge(emails, on='cust')
    print(len(merged), merged['amount'].sum())
  15. Question 15 of 15 · pandasWhat does this print?
    Python
    import pandas as pd
    
    s = pd.to_datetime(['2026-01-05', 'not a date'], errors='coerce')
    print(s.isna().tolist())
0 of 15 answered

Revise the topics in the Python for Data Engineers guide and Python guide.