Functions

--Originally published at Codebuster

Functions are one of the most useful aspects of programming, we can view them as a routine, that is to say a set of actions to accomplish something. A way to think about it is this: every morning before leaving for school I: change my clothes, brush my teeth, pack my bag, and spray some perfume, this individual actions all fall in the “function” of getting ready.

Generally, functions “take in data” (input) process it and finally “return” a result box.gif(output).

A big advantage of functions is that they can be reusable. Just like try to avoid using plastic bottles not to contaminate the environment we try not to use the same lines of codes over and over again, and instead we use a function.

Luckily, Python (like most programming languages) comes with a prepackaged, prewritten set of functions, which you can access by clicking the package.

Calling a function basically means to tell it to run. To call a function you need to type its name and the parameters in the brackets.

>>print (parameter):