Functions
Prerequisites: Variables
A function is a reusable block of code that performs a specific task. You write it once, give it a name, and run it again anytime just by calling that name.
function greet(name):
return "Hello, " + name
greet("Ada") # "Hello, Ada"
A function can accept parameters (values passed in, like name
above) and can return a result back to whatever called it. This
reuse — write once, call many times — is one of the most important
ideas in programming; later on it gets a formal name,
encapsulation, but the plain idea is simply: don't repeat yourself.