Python Function Definition and Calls
Objective 4.1 is decompose the code using functions, and the syntax is one keyword. What gets examined is what surrounds it: a function with no return returns None, a function must be defined before the line that *calls* it rather than before the line that mentions it, and a function name is an ordinary variable that can be overwritten - including one of the built-in ones.
Functions and Scope Guide 18 of 26 Beginner
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 14 min
Nothing here has changed in Python 3. Type annotations on parameters are legal and are not examined by either exam; none of this path uses them.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the function-definition objective. This matters because def is a statement that runs - so a function has to exist by the time it is called, and a function name has no protection, not even a built-in one.
- writing
def, and finding what a call gives back when nothing is returned - seeing
returnend the call immediately - learning that a function must exist by the time it is called
- returning more than one value, which strictly you cannot
- shadowing a built-in name, which nothing stops you doing
Before you start
-
def, and what a call gives back
-
return ends the call immediately
-
A function must exist by the time it is called
-
Returning more than one value
-
A function name has no protection, not even a built-in one
-
What the exam does with this objective