You already have some experience with using functions; like the input and print functions provided by Python. Based on that, you might already have an idea of just how powerful a well-written function can be!

First, let’s explore why we may want to define our own functions! In any software project, there will be a core set of logic, the logic that represents value from your service. For Twitter an example would be the ability to

In the case of input, we know that we can include a line like: choice = input("choose! ") to store a user’s input from the terminal. Let’s dissect this line to get some general info on the structure of a function.

First, look at the name of the function “input”.

Try printing this function name out to the console to get a little more information: print(input).

We can see from the output, that this is a “built-in” function in Python. This means we don’t have to define the function ourselves; it comes along with the Python installation on our machine. Often, you will be utilizing functions like this which are written by other people; either built-in or library functions.

Anytime we provide a function name, followed by parentheses, we are telling Python to call the given function. so if I write input() in my Python script and execute it, Python knows to run the code written and organized as the input function!

As you can imagine, this technique is integral to the practice of programming. We will learn to apply logic to solve a particular issue, organize it into a function, and then call it in our script!