Functions
PYTHON
def vat(amount, rate=0.15): return amount * rate print(vat(1000)) print(vat(1000, 0.05))
def defines a function with its parameters in brackets. return sends the result back to the caller. rate=0.15 is a default used when no value is passed.
PYTHON
def grade(score): if score >= 90: return "A" elif score >= 80: return "B" return "C" for s in [95, 85, 60]: print(s, grade(s))
Watch out
print inside a function only shows something; return hands back a value you can store and use. A function without return returns None.