§ 2.6section 14 of 18·~4 min
Functions
A function packages a few steps under one name so you can reuse and test them. Pipelines are mostly small functions chained together: extract, transform, load.
def add_gst(amount, rate=0.18):
"""Return the amount including GST."""
return round(amount * (1 + rate), 2)
print(add_gst(1000))
print(add_gst(1000, 0.05))
OUTPUT
1180.0
1050.0rate=0.18 is a default value, so callers can leave it out. return sends a value back to the caller. A function with no return gives back None.
on the job Names like clean_row(row), is_valid(row) and load(rows) are how real ETL code is organised. Each does one job and is easy to test on its own.