Functions in python

--Originally published at Hackerman's house

A function is a structuring element that groups some lanes of code that can be utilized many times in the program. Is basically defining a formula to then just put the name of the formula, and the program will run it without the need of writing it again.

The syntax looks like this.

def name-of-the-function(Parameters):

Statements

The statements determine what your function will do.

To call a function you just need to put the name of a function previously defined.

name-of-the-function()

This is a really simple example about how to define a function and then call it two times. What this would do is run the same function two times. It is important to note that this function has no parameters.

function

And this is how the program works.

function2

Besides this really simple program I created another that actually uses parameters.

function4

This program executes a sum of the two parameters given.

And here it is how it works.

function5

Thanks for reading me.