Calling a function — a tool with an input and an output
P41.using-functions.01 · Audience: Guest, Language professional, IT/ML learner · Prerequisites: Dictionaries — a mini table
Where next?
Later in Using Functions
Go up a level
P41.using-functions.01 · Audience: Guest, Language professional, IT/ML learner · Prerequisites: Dictionaries — a mini table
Later in Using Functions
Go up a level
You have already been reaching for tools without naming them: len(words)
counted a list, sorted(words) put it in order. Each is a function — a tool
you hand a value and it hands one back. Before this module names them, picture a
kitchen gadget: you feed it something, you get something out. This module gives
that everyday shape its Python name and puts three built-in tools in your hands.
len(words) you are calling a function. len is the tool's name; the value in the brackets — words — is the input you hand it (its argument); and the value it hands back is the output (its return value). Read it as a sentence: "give len this list, take back its length."Why it matters — Almost everything a notebook does is call a function. Once you can read one call, you can read most code — it is the same shape every time.
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.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Your turn: take a short word list, count it with len, order it with
sorted, and total a list of numbers with sum — each a
tool with an input and an output. Press Run.
Loading exercise…
Loading your notes...