Functions, not = to f(x)

Before creating and calling functions in Python 3, first we have to know what is a function in Python 3? So….

What is a function in Python 3?

A function is a code, (reusable code) that let us make a single related action. For example, the most common function I may think of is “print()” which is also an output, but Python let us create our very own functions/commands/methods.

So now we now what a function is, but now, how do we create a function?

To create a function first of all your are going to NEED the KEYWORD “def” (an abbreviation of the word define) which is indispensable to create a function, ’cause like the name says it you are going to define it, the next thing you need is the name of your function, so name it anyway you like, but I recommend its a name that reminds you what that function does or at at least is supposed to do lol. And at the end you add parentheses “()”, and inside this parentheses there should be the parameters/arguments of that function.

Here’s a more graphical example of how to create a function:

“def” + “nameofthefunction” + “(parameters/arguments)”

Screenshot from 2016-08-29 11-04-41

That is my creatingandcallingfunctions.py file and when I run it on the terminal it is suppose to print 14 lines of series of numbers.

Screenshot from 2016-08-29 11-08-25

and we are done 🙂

 

Here is a link for a youtube video which explains and also gives an example of what are functions in Python3 in only 3 minutes.

 

Leave a comment