Functions

What are functions?

A function is a named section of code designed to perform a particular task. A function can be called whenever that task needs to be performed, allowing the same code to be reused rather than written repeatedly.

  • A function contains a set of statements that perform a specific task.
  • A function is given a name so it can be called when needed.
  • The code inside a function does not run until the function is called.
  • A function can accept input values called arguments and can return a result.

Definitions and vocabulary

A function is a sequence of program instructions that performs a specific task and usually returns a value. This function (block of code) can be called (used) throughout the program by its defined name.

In computer science, functions return a value. If a function does not return a value it is called a procedure. In Python, the def keyword is used for both of these as all 'functions' technically return something, even if it’s just None.

For VCE Applied Computing, you need to know the difference between a function, a method and a procedure. We will cover methods later in the course.

Further reading

Here you would be directed to a source of additional reading.