Python Fundamentals

Core Python syntax, data structures, functions, modules and error handling, with the emphasis on what data pipelines use most.

Beginner · about 15 hours · difficulty 2/5

Python is the default language for data engineering: Airflow DAGs, PySpark jobs, ingestion scripts and tests are all Python. You do not need to be a software architect, but you must be fluent.

What to master

  • Types and data structures: str, int, float, bool, None, lists, tuples, dicts and sets. Know when a set or dict lookup beats scanning a list.
  • Control flow: if, for, while, comprehensions ([r["city"] for r in rows if r["amount"] > 0]).
  • Functions: arguments, defaults, *args and **kwargs, return values, small pure functions.
  • Modules and imports: splitting code into files, the standard library.
  • Exceptions: try, except, finally, raising your own errors with clear messages.
  • Strings and dates: f-strings, datetime, time zones (IST vs UTC matters for every Indian business).

Data-flavoured practice

Write functions that take a list of dicts (rows) and return aggregates, deduplicate by key, or group by a field. These are the same operations you will later do in SQL and Spark, so learning them by hand builds intuition.

Generators and iterators

yield lets you process a file or API response row by row without loading everything into memory. This is how you handle a 10 GB file on an 8 GB laptop.

Pitfalls

  • Mutable default arguments (def f(rows=[])) that leak state between calls.
  • Catching every exception with a bare except: and silently continuing. Failing loudly is better than loading bad data.
  • Mixing naive and timezone-aware datetimes.

You are ready to move on when you can write a script that reads a list of transaction dicts, converts UTC timestamps to IST, and returns total amount per day without using pandas.

Key concepts

  • Data types and data structures
  • Control flow and comprehensions
  • Functions and modules
  • Exceptions and error handling
  • datetime and time zones
  • Generators and iterators
  • Classes and dataclasses
  • Decorators and context managers

Mini project

Write a pure-Python module that takes a list of order dicts and returns daily GMV, order count per city, and duplicate order ids. Add a small main block that runs it on sample data.

Check yourself

Why would you use a generator instead of a list when reading a 20 GB log file line by line?

Free resources