GCSE · Computer Science · Eduqas · Spec C500QS
Creating and extending Python 3 functions/methods
A function prints 7 on the screen, but when you ask it for its answer, Python hands you None. Where did the 7 go?
Computer Science · Functions
Predict the call before Python does
Call each marked step before the table shows it. Nothing is run here: every value comes from a program that was checked in real Python 3. The screen row shows what has been printed so far, and it is not a variable.
def say_sum(a, b):print(a + b)def take_away(a, b):return a - bprint("done")total = say_sum(3, 4)print(total)gap = take_away(10, 4)print(gap)
Variables
Step 1. Worked for you. The def line only writes the recipe down under the name say_sum. Neither body line runs.
Ask yourself three things: what is printed, what does the variable hold, and where does control go next?
Computer Science · Extending a function
Extend greet() without breaking it
greet() used to take just a name. It has been extended with a greeting, and the program below calls it three times. The last call should greet Ben with "Hi". Press Run, read what Python says, then choose how to fix the flagged line.
- def greet(name, greeting):
- print(greeting + ", " + name)
- greet("Sam", "Hi")
- greet("Priya")
- greet("Hi", "Ben")
Every message and output here is what Python 3.13 gives for these exact programs. Other Python versions word a few messages differently.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Define it, call it, and know exactly what comes back.
What you need to know
- A function is a named, reusable block of code. You run it by writing its name followed by brackets.
- To define one in Python 3, write def, the name, brackets holding any parameters, and a colon. The indented lines below are the body.
- Defining a function does not run it. The body runs only when the function is called, and the def must be executed first.
Have a goJo writes def hello(): and print("Hi") indented underneath, runs the program, and says "Why is my screen empty?" What would you tell Jo?
The function has only been defined. Jo needs to call it by writing hello() on a later line.
Jo thinks the def line runs the body, but def only writes the function down. The body runs when the function is called.
- Parameters are the names in the def brackets. Arguments are the values in the call, matched in order unless passed by name.
- With several parameters, every one without a default needs an argument. Too few arguments, or too many, raises a TypeError.
- return sends a value back to where the function was called, and ends the function at that line. With no return, you get None.
Have a goA function has return 5 on one line and print("hi") on the line below it. Does hi appear when you call the function?
No. return ends the function at that line.
It is tempting to think every line in the body runs, but the moment return runs the function is over, so lines below it are skipped.
- A returned value can be stored, printed, or used in an expression. Commas after return send back several values together, as a tuple.
- To extend a function, give a new parameter a default value so old calls keep working. Defaults go after parameters without them.
- A method is a function that belongs to an object, called like name.upper(). String methods return new values; append() and sort() change the list and return None.
Have a goPriya writes scores = scores.append(7) and expects the longer list back. What does scores hold afterwards?
None.
append() changes the list in place and returns None, so assigning its result to scores replaces the list with None.
- Write your own method with def inside a class. Its first parameter, usually called self, is the object, and Python passes it in for you.
The big picture
A function is a named block of code that you define with def and run by calling it. Arguments fill the parameters in order, return sends one value back and ends the function, and a function with no return gives back None. A method is a function that belongs to an object and is called with dot notation. Extending a function, for example with a default value, lets it do more without breaking the calls you already wrote.
Key points
Worked example
Problem
What does this program print, and why? def label(name, tag="Guest"): return name + " (" + tag + ")" print(label("Ana")) print(label("Ben", "Admin")) shout = label("Cy").upper() print(shout)
⚠ Watch out
Treating print as if it were return. A function that only prints shows the answer on the screen but gives back None, so total = add(3, 4) leaves total as None. Methods catch people the same way: scores = scores.append(7) leaves scores as None.
Memory hook
def writes the recipe, the call cooks it, and return serves the dish back to whoever ordered it. print just shouts the answer across the kitchen.
Check yourself
A function does print(word.upper()) and you call answer = shout("hey"). What appears on the screen, what does answer hold, and which one change makes answer hold "HEY"?
Flashcards
(14)What does the def line do when Python reaches it?
In def area(w, h): and the call area(3, 4), which are the parameters and which are the arguments?
A function has two parameters and no defaults. What happens if you call it with one argument, or with three?
What are the two jobs of return?
What does a function with no return statement give back?
How do you send back more than one value, and what do you get?
How do you give a parameter a default value, and why do old calls keep working?
Is def f(a=1, b): allowed?
What is a keyword argument, and why use one?
What is a method, and how do you call one?
Does word.upper() change word?
What do append() and sort() return?
In a method written inside a class, what is the first parameter and who fills it?
Name the benefits of using functions.
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Eduqas GCSE Computer Science topics
- Abstraction
- Analyse a set of requirements
- Authentication management routines
- Comparing approaches to requirements
- Consistent programming style
- Creating and extending Python 3 libraries
- Decomposition
- Designing a testing strategy
- Explaining test outcomes
- File handling: open a file
- File handling: read into a variable
- File handling: read into an array
How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 16 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.