Functions in Python

--Originally published at Hector Martinez Alcantara

Hey there, i’m going to explain how to create and use functions in python 3. First, a function is a process that repeats several times and to reuse code, you use a function.

In the next example we can see a definition of a function:

def Litleman(Amaterial):
   print(' 0')
   print(' /T\\')
   print(' /\\')
   drawing= 'A man of '+ Amaterial
   return drawing

The word def inicates that we’re creating a function, then you put the name of the function, and in parenthesis a parameter of any type, which is a variable that will be used in the function, finally, you put the word return, to get back in the code, you can return a parameter.

Here is an example of how to cal a function:

Littleman('Steel')

It’s very simple, you call a function by it’s name with parenthesis at the end, and in the parenthesis you can introduce a parameter like the example above.

Here’s an example of the result of the function:

Littleman('Steel')
  0
 /T\
 /\
'Its a man of Steel'

It’s very simple right?

Now you know how to create and use functions!

Thanks for reading, have fun!

Special thanks to Barron stone on Programming fundamentals in real life from lynda.com