Programming Basics
What Is a Function in Programming?
A function is a named, reusable block of code that takes inputs called parameters, does one job and can return a result.
Definition
A function groups a few lines of code under a name, so you can run them again and again by calling that name. It can take inputs, called parameters, and send back a result with return.
Functions keep programs short and readable: you write the logic once and reuse it.
How it works
When you call a function, the values you pass (arguments) are assigned to its parameters, its body runs, and the return value takes the place of the call in your code.
Variables created inside a function are local: they exist only while it runs and cannot be seen from outside.