 Okay, this video, we're going to talk about functions in depth. Specifically, we're talking about arguments and parameters and different ways of doing things. For example, you can have a function inside of a function. That's crazy. So let's dive in and take a look. Okay, let's start off nice and simple. We're talking about no arguments, no parameters. We're just going to do what we've done before just so we can have a good base to start with. We've done this multiple times by now. So we're going to just print this out. And we're going to say normal function. This is kind of our starting point here. We're going to go on a little bit of a journey. And what we're going to do is we're going to dive into the mouth of madness and just see how crazy this can get. So we're now going to just call this. You notice how I put this right here. These are escape characters return line feed with some dashes and arguments. We're going to break this up because we're going to have a lot of output in this video and we want to be able to see what's happening here. So I'm going to just copy and paste these as we go. We're calling this function and it works as expected. If any of this seems unclear at this point, you need to stop watching this video and go watch the previous 16 videos to really wrap your head around what we're going to be talking about. Because we are going to no holds bar just dive right into the deep end. Let's take the training wheels off. We're going to talk about positional and keyword arguments. Okay, this is where it's going to get really confusing and really fast. So we're going to make a function called message, we're going to say name, message, and then we want an age. So we've got a couple of different data types we're going to be working with. Pretty clearly, it's going to be like a string string and an ant. So we're going to say print. Hello. And then we want the name, followed by the message. You are and then however many years they tell us. So fundamentally, this doesn't seem like rocket science, but we can start doing some really, really crazy things. So I'm going to just put that out there positional keyword arguments. So when we run this, we'll see the output broken up. Let's go ahead and say message. And let's call this as you would expect it. Now, what we're doing here is called positional. You notice how there is name, message, and age. Those are the positions. Think of this like a list. It's zero base. So zero, one, two. We don't have to give it an index. It's smart enough to know what the index is. But I'm going to say Brian. Let's say good morning. And then let's give it an age. Let's say I'm 22. Boy, I wish I was 22. I'm really not. And that's positional. Go ahead and run this and we'll see. Sure enough. Hello, Brian. Good morning. You are 22 years old. So it looks great. Let's grab this and let's play around with it a little bit here. We're going to use positional, but we're going to use the wrong order. Let's go ahead and screw this up. So I'm going to say 22. And good morning. So really what we're doing is we're switching these around here. The output suddenly makes no sense. Hello, Brian 22. You are good morning years old. That makes absolutely no sense. It's like a serial killer wrote that or something. All right. So what we've done here is positional and we've screwed up the order. So how do we fix that? We use what's called keywords. So we're going to do the same thing. I'm going to say message. And here we're going to say msg equals. You can see this in Visual Studio Code. It's got that parentheses and little bitty block there. It's smart enough to know that we are trying to call the parameter message with the argument of good morning. Now you notice right off the bat we are completely disregarding the order because message is, well, the second one and we're giving it first. As you're about to see, it really does not matter. Say age equals say 46. And then name equals Brian. Go ahead and run this. And sure enough, it says, hello, Brian. Good morning. You are 46 years old. So now it's working as expected. We don't have to give it a specific order. We are working with e words. And I wish they would have called this grammatical arguments or something like that. But basically it's keywords. So what's happening is Python is taking these parameters here and turning them under the hood to keywords. And it has some sort of internal list. And it's saying, Hey, if you give me a keyword and pump it in there, it will just magically know how to line those up and what order they need to go into. You can also do both. So let's just grab this guy. Let's grab this. And say Brian. And then let's go ahead and flip these around. So you can mix and match these as you want. So you can say positional followed by keyword. Let's run that see it in action. Doesn't matter which way you do it. It just works. Extremely cool. And I absolutely love that about Python. Let's make this ever complex. Still, we're going to talk about internal or inline functions. And there is a subtle difference between internal and inline. We're talking about an internal function, which is essentially a function inside of a function. So we're going to say counter. And inside of counter, we're going to immediately call another function or create another function called display. We want to say count will zero. So really all we're doing is we're saying a function in a function. And notice how it's smart enough to drop us down a line. So it knows it has its own scope. And we're just going to print this out. And we're going to say internal. That way we know I was going to do it something else, but let's just say internal. So we know where we are. And then print that count out. Under the hood, this is really complex. But it's super simple the way we do it. We just have a function. We've defined another function that function gets its own little scope. And we can now drop out here and say something like this. 4x in range, say five, nothing too drastic here. Let's go ahead and call our function display. And we're going to call that with x. So we're saying 4x in range. So it's going to do that five times. And it's going to say call display one, one, two, three, four, five. Interesting how that works. Let's see this in action here. A little bit of copy and paste action for my notes. We're going to talk about internal functions and we're going to call the counter function. Sure enough, zero, one, two, three, four. I always forget that's zero based always trips me up. Okay, so what we're doing here is calling a function, which has an internal function, which is calling it internally. And it's just kind of going around in time and doing all this madness for us. So let's take this counter, grab this internal function called display and try to call it. So we're now going up a notch. Now let's just see if we can call this. Sure enough, we cannot we get a name error, display is not defined. Remember when you see is not defined, that means Python has no idea what this is because it does not exist in the scope we're working in. So you guessed it, you collapse that down. Display doesn't exist. It's inside of this scope over here. It's super cool, but it's also super confusing. So if you're going to use this, be very careful about how you try to call it or you're going to get some sort of error. All right, let's give you a nightmare scenario. Boss walks in, you're a newbie Python programmer and he says, I want you to make a function, but I'm not going to tell you how many arguments I'm going to give you. I want your function to automatically figure it out. Well, what we're talking about here are star args and star stands for wild card. This is a positional variable length argument. All right, so what are we talking about positional? Well, we've talked about this a little bit before up here where you have a position and that's not so much what we're talking about. We're talking about this right here, we're gonna say def and let's go multiply star args, we could name this whatever we wanted. Now we're going to feed that a bunch of arguments and they're going to be based in a position. So let's go see equals one, four, num in args. Let's go ahead and print that out so we can see what's going on. Now we're just going to multiply that we're going to say z is multiplied by the number. Let's go ahead and print this out. A little bit of copy and paste action for my nose just so graphically in the output, we can see where we are. Let's go ahead and call this. I'm going to say multiply or multiple actually. And we're going to say boss gives us three numbers here. Number one, number two, number three, this is what I mean by positional. It's going to take the exact order we give it one, two, three, we could switch this around and say two, three, one, and you'll see the position changes two, three, one. All right. Very, very simple, very easy to wrap your head around. The major takeaway here is we're not constrained. We can take this out to just some ridiculous level. We could do something like this. It works as expected. Let's take that same nightmare scenario where our boss is just a complete jerk and we're going to say, okay, he's going to come in and say, I'm going to give you random information. I'm not going to tell you how much information might give you and I'm not going to give it to you in a specific order. Yes, that's a nightmare. So what we're talking about is keyword args, which is basically the same thing except for instead of positional, we're using a keyword. We've talked about keywords before way back up here. We can mix and match and do all this other cool stuff, but we're going to try and dumb this down and make it a little bit simple because yes, this can get complex fast. Major thing to note is there are two asterisks here, two stars. So let's go ahead and say def profile. This is what the boss is going to do to us. He's going to say, I'm going to give you a person and the person is just going to be a bunch of data and you need to figure out what to do with it. So we're going to print out our person. Now let's jump out of there for just a moment here. And I'm going to say add our little delimiter here so we know we are in our output and let's go ahead and call this. So I'm going to say profile. Now it's smart enough to know choosing keyword arcs. So it gives us that double asterisks. And now it's on us to define what information we're going to give. And I'm just going to say name. And if you're wondering where I'm getting a name from, I'm literally just randomly grabbing something out of my mind. It doesn't matter what we give it here. So I'm going to say Brian. And then let's go ahead and say age equals 46. Let's run this and see what happens. We're printing out this person. So notice it's now converting that into a dictionary. That's right. So now we can just use this like a dictionary. It's extremely cool the way this works. All right, let's go ahead and use an internal function. I'm going to say f display. Let's go ahead and display k. Now we're going to do a little bit of test here. We've covered this in our dictionary video here where we're going to say if k is in the person keys, then we want to print this out. And if that's super confusing, I would highly encourage you to go back in the playlist and watch the video where we cover dictionaries. So now we can just work with this dictionary directly. So we have a function in a function, this internal function display is just going to say if this keyword is in person keys, because remember it's converting it to a dictionary, then go ahead and print out the key and print out the value. Now that we have our little internal function, let's go ahead and call it. So I'm going to say display and let's give it a keyword name. Now notice how we're actually hard coding this. You can do different things like this. So I'm going to say name, age, and we're in a meeting and they were talking about adding a pet, but they didn't actually do it yet, which is why we're saying if the keywords in the keys. Because we've done this, if we don't have to worry about not defined, it's going to print out name, age, okay. Someone in marketing comes back goes, wouldn't it be really, really cool if they had a pet? So let's go ahead and add that in there. Now you can see Brian 46 and cat and we have our two different calls here. So we have the first one that does not have the pet and the second one which does have the pet. And it just works the way you would expect it to. And we can now test this for other things. So for example, let's say food equals pizza. What have we done here? Well, we've added a keyword that we're not using. It does not crash your application because it's saying if it's in there and we haven't even called it. So let's do the opposite here. Let's go here and let's say thumb as I don't know what that is, we're just goofing around. It doesn't crash because it's not in there. Very cool, very easy the way this works. Super simple to wrap your brain around. But what we're really trying to drive home here is these are keyword arguments, not positional. The position simply does not matter. Okay, let's wrap this up with a brief conversation about Lambda or anonymous functions, you're going to hear called Lambda functions, they're actually not Lambda functions, they're anonymous functions. We use Lambda to create an anonymous function. So let's go ahead and define this real quick here. So first things first, we're going to make a normal one, just as a point of reference. So I'm going to say def and let's call this make sqct. So we're making the square footage, we're going to say the width, the default and the height with the default. And we're just going to return the width height. So we're just really getting the square footage here. Super simple, super easy to understand. Go ahead and print this out. Let me say print. Actually, I'm going to pause for just a second and we're going to add in our little delimiter here so we can see it in the output. All right, back to what we're working on here. We are going to print out the square footage and let's go ahead and do this both ways. We can say width equals, trying to think of a good number here, 10, the height, anybody out in the audience, anybody, anybody, let's call it eight. Why not? We can also just say print and then make the square footage and let's say 15 by eight. We can call it both ways. Go ahead and run that and you see, there's our numbers. Now let's use the lambda keyword to create an anonymous function. I intentionally called it a lambda function even though they're anonymous functions because you're going to hear people say, well, I'm going to create a lambda function. We're actually using the lambda keyword sqft equals. So what are we doing here? We're making a variable. We're going to say lambda and let's go ahead and define some things. Now I want to kind of slow way down. I'm going to plop a note in here. There's a certain format we have to do this in. So we have a variable, the lambda keyword, a list of one or more variables, and then some code. So we're saying lambda. Let's go ahead and say width equals and let's say zero, height, zero, fallen. And now we're going to our code. So if you're looking at this, really what we're doing is we're saying lambda is going to replace all of this. Then we have our information. And I specifically named these the same so you could see them highlighted on the screen. Let's do that again. So now we have our parameters. Now we have our code. Now if we wanted to, we could just grab these and through the magic of copy and paste instead of a function call to make square footage, we're going to just all this variable sqft and it functions exactly the same. See 81 20, 81 20. This is just witchcraft. I mean, this is like voodoo magic from old school programmers like me. But so what's really going on under the hood is when you call lambda, Python is basically making this, but it's doing it all in one line. So as a programmer, it makes your life a little bit easier because it's all in one line. And you just have to remember this variable name and it exists out in the global scope. So we can treat it just like a function. If we mouse over this, you see it's smart enough to know that it is a call to lambda. So it is making an anonymous function. I personally am not a huge fan of anonymous functions, but they do have their place on the programming world, especially if you get into like GUI programming and socket programming and things like that, you'll see people use these very heavily. Some people love them. Some people hate them. I personal my personal preference is I like to actually define what I'm going to use rather than relying on some crazy witchcraft. But I don't want to steer you away from this lambda is very powerful and very useful. I hope you enjoyed this video. You can find the source code out on github.com. If you need additional help myself and thousands of other developers are hanging out in the void realms Facebook group. This is a large group with lots of developers and we talk about everything technology related, not just the technology that you just watched. And if you want official training, I do develop courses out on udemy.com. This is official classroom style training. If you go out there and the course you're looking for is just simply not there. Drop me a note. I'm either working on it or I will actually develop it. I will put a link down below for all three of those. And as always, help me help you smash that like and subscribe button. The more popular these videos become, the more I'll create and publish out on YouTube. Thank you for watching.