 This video is the first in a series of a couple of videos talking about functions in Python. So, let's first go ahead and create a new notebook file and rename it into functions.ipython notebook. So, in this first video on functions, we are going to look into built-in functions, how they work, what they are, and so on. So, let's make a little header here, call it built-in functions. And we have seen a couple of built-in functions already. So, to start with an example, let's first create a list of numbers. And these are the numbers we used in the first example in this course. So, these are the numbers from 1 through 12 in no particular order. And what we've seen in the previous video is that we can simply sum up and count the numbers in a list. So, what did we do? Well, we used the built-in function sum and we call it with the so-called call operator. So, without the parentheses, sum is simply a reference to a function object in memory. However, with the parentheses, the call operator, we are going to execute this code that is inside this function, so to say. And we give it as an input simply numbers in this case, the list. And we get back the sum of all the numbers in the list. Similarly, there is a built-in function called len. So, if we simply evaluate the expression len, then we get back a reference to the len function. And let's call it also with the numbers list as the input. And we get back at 12, because we have 12 numbers in the list here. Okay, so first of all, you may wonder what are the functions that Python knows. So, to find out, let's go to the Python documentation. And on the main side of the Python docs, let's scroll down and go into the library reference. So, you see that there are a couple of options. And library reference is the option, the page that talks about everything that Python knows, either right after installing it or after, as we will soon see, importing something from the so-called standard library. And if we scroll down, the first couple of sections here in the table of overview start with the word built-in. And built-in means we can just use it without importing it, without doing anything. We can just use the functionality described here. So, let's click on built-in functions. And here we see indeed a list of all the functions that, in this case, Python version 3.9 knows about. And here we see the sum function. And under L, we also see the len function. So, as a beginner, looking at the official documentation may be quite daunting. However, my recommendation is try to get used to reading the documentation. So, let's maybe do one example. Let's click on sum. And this takes us all the way down to the documentation of the sum function. And so, let me maybe briefly talk about what we can see here and how the so-called syntax or the convention here in the documentation is. So, first we have the name of the function simply sum. And then we also have the parentheses here. The parentheses here, they are not really the call operator to execute the function, but they are simply a convention. Let's call it the bounding, the bounds of the so-called parameter list. So, the parameters are the inputs that the function takes. In this case, we have a first input, which we call iterable. The first parameter is iterable. We will learn about iterables in a future video. But for short, iterables are any object in Python that we can loop over. Okay? So, just like a list object. Then we have the slash. This is a rather recent addition to Python. So, what the slash means, we will also learn in a future video. Just for now, simply ignore the single slash here. And then we have the second parameter start. And this is set equal to zero. So, what that means is the sum function takes either one or two parameters. And in case where we don't give the function a second input, then the second input start, the parameter start, is automatically set to zero. So, in other words, zero is the default value. Okay? And so, what this function does is it sums up all the elements inside and iterable inside an object over which we can loop. And it starts to count, so to say, at the number zero. So, our very first example of this course, what I did is, when all what we did is we found the average of all the even numbers in the list. And if you go back into this video, you will see that we did that with a for loop. And before the for loop, we initialized a variable called total and set it equal to zero. So, there was a logic that we would otherwise refer to as a running total. That's basically what we calculated. And the sum built in function works similarly. So, it takes an initial value and the most common initial value for, you know, summing something up is always zero because we want to simply start it zero. But we could also start at some other number. Okay? So, this is how you read documentation. Okay? If you have inputs and the inputs that don't have a default value, these are the required inputs. And the inputs that do have a default value, we don't have to give it to the function, but we could. So, let's go back to the notebook here. And let's maybe make a second example where we call some function with the numbers list as the argument and let's give it a start value. So, for example, let's give it the start value of two. So, previously the sum was 78 and now the sum should be 80. And it is. Okay? And so, that's how we can read the documentation and know what we can do with it here in the notebook. Okay. So, these are built-in functions. And we have seen a couple of more functions in previous videos. So, one other example is, of course, the id function. And the id function gives us the identity, so to say, or the memory location of an object in memory. So, the interesting thing in Python is, and for a beginner, this may be a little bit subtle, but you should have that in the back of your mind. In Python, everything is an object. So, even functions. And as a beginner, I don't assume other programming languages. So, in many other programming languages, functions are not necessarily objects. So, functions often work different than other objects in many programming languages. In Python, however, they're quite similar to other objects. Okay? So, for example, if I go ahead and I ask for what is the id, let's say, of the sum function, we see that we get back a memory address. And that basically confirms that the sum function itself is just another object. And another function that we saw previously is the built-in type function. And the type function is quite interesting, because it gives us back the type of an object in memory. So, everything in Python is an object. And every object always has exactly one type, a data type. And a data type determines how big the object is, how much memory it occupies, but also what we can do with it. And let's call the type built-in function with the sum function or a reference to the sum function as the argument. So, what I mean by with a reference to a function is we simply mention the function without parentheses. So, otherwise, I would have opening closing parentheses here. We don't do that. So, we simply pass on a reference to the sum function as the input to the type function. Let's execute this. And Python tells us that the sum built-in function is indeed a built-in function or method. And what the method is, we've also previously seen. So, a method is just a function that is attached to an object. But we will look into that very late, so to say, in the beginner's course. That's a bit of an advanced topic, but it's also nothing that is too hard. Okay. So, in other words, let's maybe briefly look into what that looks like in memory. So, when Python starts up a new process, what it automatically does, it occupies the memory with some stuff. So, for example, and here let's abbreviate that, that the data type will simply func for function. And for example, this is the built-in function sum. Okay. So, the built-in function sum is already as an object in memory. Okay. You don't have to import it. And the same holds true for other functions as well. And because of this pattern, that means the sum function also has an ID, also has a data type. And inside the box, we have basically ones and zeros that basically resemble the code that is inside the function. Okay. So, let's continue here. So, in other words, we have seen now how to use functions. And now I want to introduce another technical term that is quite useful to know. And in particular, it's quite useful to know when you want to learn how to read the documentation. And that is the concept of a callable. So, maybe let's make that bold, a callable. So, that is a generic term for an object that can be called. And called is just another word for executed. So, you may now wonder, well, what may there be, except outside of a function that can be called? Well, technically, we could design our own objects to be called. So, it's not just functions that are callable in Python. So, in particular, there is one special breed, so to say, of functions that we would actually not consider functions, but they work like functions. And these are so-called constructors, or constructor functions sometimes called. So, what we have seen in a previous video is that everything, every object has a type. And for example, if we go ahead and let's create a variable A and set it to 42, we saw that the type of A is simply int for integer. So, that's the data type of the object. And all the data types have in common that we can use them to take any object that we may have and cast it, that's the technical term, as an object of this data type. So, for example, let's go ahead and look at the number 42.0 at first. So, this would be a floating point number, as we saw previously. But let's say I pass it on to the int constructor. So, I use int, the data type int, and I call it just as if it were a function, and I call it with the call operator, and I pass on, in this case, a floating point number, and I get back an integer number. Okay? So, that is what I mean that I can use the int data type just as if it were a function. So, it looks like a function, but technically speaking, it is not. It is a so-called class. This is something that is a bit advanced. So, we will learn that in a later video. But a generic term for anything that can be executed is just a callable. Okay? We have seen two kinds of callables so far in this video. We have seen built-in functions and also classes. So, in other words, constructors. Let's keep the name constructor for now. And in a video quite soon, we will see another third kind of a callable, which is a user defined function, which is a function that we create ourselves. Okay? So, that is constructors. And technically speaking, in Python, there is a built-in function called callable, and the callable function returns either true or false. If the object we pass it is callable or not. So, let's say, let's go ahead and let's pass, for example, the sum function to callable, it confirms it is true. So, we can indeed call some function, but we knew that before, right? We called the function above. Also, the int constructor is callable. However, to show you an example of something that is not callable, let's look at our list that we created up there, the numbers list. And the numbers list, as a list object, it is not callable. So, that kind of makes sense. I mean, why would you execute a list object? A list object is only there to basically hold many, many elements. But yeah, so that is how we can introduce or how we can use the concept of a callable. And sometimes in a bigger program, it may, you may not be certain if an object can be called or not. And then you can quickly check that with the callable built-in function to confirm, hey, can you call it or can you not call it? Okay, so that is our brief introduction into what functions are, how they work and how you can look them up in the documentation. We learned about the concept of a callable and also the concept of a constructor. And other constructors exist that you already know, for example, the float constructor. So let's quickly do that as well. If we took 42 as an integer, of course, we can go ahead and call the float built-in and we get back 42.0. Okay, so that is it for this video. In the next video, we are going to learn how we can create our own functions. So see you then.