I’m bringing functions back.

--Originally published at Carolina's Blog Site

So kids, a function is a named sequence of statements that performs an operation/computation. Functions may or may not take arguments (which are like the ingredients that change depending on what result you want to achieve in that particular occasion).

To define a function,

  • you write def followed by the name of the function,
  • then you write the parameters/arguments in () and you end with a “:”
  • In the body of the function, which has to be indented, you type the order of the statements you want that function to do.
  • To finish off a function, type return and specify what the function will return. If you don’t want to return anything, just leave the return line blank.

Later, you can “call” the function by its name, and just type the parameters for that occasion.

Btw, you can have parameters that have a default value, for example: (parameter1, parameter2, parameter3=55.

souce: http://www.relatably.com/m/functional-programming-memes