Guided pathThis is part of Understand Transformers & BERTBack to the path

Writing your own tiny function

P41.using-functions.02 · Audience: guest, language-pro, it-ml · Prerequisites: Calling a function — a tool with an input and an output

Real LLM grading for this pageLLM grading (this page):

Some tidying you do again and again: capitalise a heading, trim a stray space, tag a term with its length. Doing it by hand each time is where mistakes creep in. When a small task keeps coming back, you can wrap it up once, give it a name, and reuse it — the same way you called len and sorted, except now the tool is yours. This module writes your first two-line function.

Step 1 / 3def names a new tool
ⓘ Concept: def is how you make a function
def — short for define — starts a new function.def greet(name): reads as "define a tool called greet that takes one input called name." The input in the brackets is a stand-in: whatever value you pass in later arrives under that name inside the function.

Why it matters — Writing your own function is the moment the notebook stops being a calculator and becomes yours: you name a task once and reuse it forever.

Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Ctrl/Cmd + Enter to send

🎓 Practice ladder

1 graded rung · ~5 min

Your turn: write a two-line function that takes a word and hands back a small fact about it — its length. Define it with def, return the answer, then call it. Press Run.

Explorer rung — write a two-line function

Loading exercise…