Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Subprograms

Functions

All topicsPractise exam questions
Knowledge organiser

Subprograms

301.12c

Return a value to program.

What you need to know

A function is a subprogram that calculates and returns a value using the return keyword. The returned value can be stored in a variable or used in an expression.

Key points

  • Uses return to send a value back
  • result = my_function() stores the returned value
  • Can return any type: int, str, bool, list
  • Function ends immediately when return is reached

Code examples

Function with return
python
def calculate_area(width, height):
    return width * height

area = calculate_area(5, 3)
print("Area: " + str(area))  # Area: 15