ProLesson 3 of 36 min read

Functions: reusing code with parameters and return values

See how functions package code under a name, take inputs through parameters, and hand back results with return.

As programs grow, you notice the same few lines appearing again and again. Copying them is risky: if you find a bug, you must fix every copy. A function solves this. It packages a set of steps under a name so you can run them whenever you need, with different inputs each time.

Vidi Pro

Keep going with Pro.

The first lesson of every class is free. Pro opens every lesson in IELTS, Programming, Mathematics, Science and Data and AI, with practice questions.

Already have Pro? Log in to keep reading.

Written with AI help. Spotted a mistake? Tell us.