 Hey, what's up guys root at no shell comm here today, and we are going to be looking at some more Python code Today, we're going to be checking out some basic Python functions And now you might often hear the the name functions or methods and these are really the exact same thing They're just two different names some languages call them different things some people call them different things But they really are just the two different names for the same thing But what they really are is a sort of process or like a system or a function or a method and hence the name that That does something that can do whatever you want it to it can take in data It can do as many things as you would like it to do with that data and that could return some data Once it's done. So today, let's check out functions in like the simplest sense I'm gonna get idle started up and you can do the same and I'm gonna create a new window with control n I'm gonna type in my shebang line I suppose you don't have to if you're not on Linux, but if you're not on Linux, you should wonder why you aren't I'm gonna save this as file dot Python I'm gonna overwrite it because I think it's already there, but let's give it a go So now let's let's give ourselves a little prompt or at least let ourselves know what we're doing though Let's type in let's run a function There we go, so now in Python functions are formed with the preceding keyword def or DEF you can see it light up if you're writing an idle and I feel like this means define and this is exactly what you're doing in here You are defining the function so you can call the function whatever you want It's almost like a variable in this case. I'm gonna call mine get info and We are going to need two parentheses where you would normally be typing in parameters But I don't think we need new parameters In fact, we don't since we're gonna be using it as the simplest case today So I'm just gonna put in a single comment here I'm gonna use a multi-line comment so I can end it in that same line That might not make a little bit of sense, but I'm just gonna type in we don't need any parameters But they would go here So that's incredibly long and lengthy and you normally wouldn't have that in a function declaration, but hey Okay, so now we're gonna need a colon and a colon usually represents a Code block in Python. It represents something new that's coming up. That is a different sort of structure so Here is when you're gonna want to hit enter and indent your line if it hasn't already when you're indenting you're bringing in a New thought it's a new function. It's a new it's a new keyword. It could be a conditional statement It could be a loop. It could be anything, but in our case. It's a function. So Just to make things a little bit Actually, let's get this out of the way first though when we're outside of it when we're outside of the function We're on a different line. So let's say print. This is outside the function and Inside let's print. This is inside the function Now See this this little white space here the tab that like sort of differentiates this lot this this function between the rest of the code That is how Python enforces white space. It forces you to have a little bit of an indent and This is so you can separate your code your functions your ifs your else's from your functions from your Backs and forth yada yada yada anything now for some people it might just be a specific style It is definitely a specific style of mine to use a single line comment at the end of at the beginning and end of a code block Just so I can see clearly. This is the beginning and this is the end That is all about style and that's kind of what I was talking about in the last tutorial the last the last guide So that's kind of why I want to let you guys know it's an option It's what you can do if you feel like that little indent is enough for your eyes and you can tell it apart That's that's fine. Do your thing, but I myself am going to stick with my little comments here. So I'm gonna get rid of these things inside and outside of the function though. Actually, let's try it I want to show you guys something pretty cool So we have something that's inside the function in one thing and one thing that's outside the function So if we if we check out our program first we print let's run a function Then we define this function and then we go back to printing. This is outside the function inside the function We're printing. This is inside the function. So let's go ahead and run this. Let's just hit f5 and it's oh There's an error in my program invalid syntax. Oh What do we got here? Is this comment something wrong? Let me uh, oh I have a I Don't want to use that apostrophe. It might it might have a temper tantrum Let's widen the sound a little bit and let's go f9 f5. That's what it is There's an another error in my program screw this comment screw this comment It's giving me too much trouble, but just know that this is normally this Section in between these parentheses is where you'd be putting parameters if you were to use If you were to use those parameters and those arguments I'm gonna get in that in a later video until then it's just really embarrassing that I had so many errors But let's go f5 Okay, let's run a function. This is outside the function awesome Wait a second. That's not awesome. That's not what we wanted whatsoever. We were hoping that it would print This is inside the function. Well what you see here is we have defined the function But we haven't called it What you do is once you finish defining the function you can type in the name of the function and then your Parameter and then your parentheses then you would fill in the parameters as you need But we don't have any parameters. So we don't have to worry about that So let's run a function. We have find the function then we run get info and then we print out this is outside the function So if we do it again, let's run a function. This is inside the function. This is outside the function Awesome, this is what we wanted because we're calling get info So I'm gonna comment this out for the moment this and I don't think we even need This this last line, but what I want to do here. Let's let's give it a little bit more functionality Let's type in a user input equals raw inputs What should we say? What should we say? I'm gonna give it a new line here. So it's a little bit cleaner and Let's print Let's say Tab and then whatever the user types in so now we'll run that Except we have to remember to uncomment that function call Run it again and let's run a function. What should we say? What should we say? Let's say Python is the coolest Language ever Python is the coolest language ever there our functions done. What if we ran it again? What if we ran it another time another time? What if we ran it as many times as we wanted to? Da-da-da-da-da-da-da-da-da-da-da see oh, I got an error now But it's gonna keep doing that over and over and over again. It's it's almost like we've taken all this code That's inside the function and replace it with a single line here. That makes things so much easier Especially if we have a whole like a big algorithm or some sort of Process that we need to do over and over again and and it should vary depending on the data that we're passing to it And that sort of thing so that's what we can do here. That's exactly what we can do here and That's awesome that allows us so much more functionality. That's kind of a pun And in our programming because we're able to manipulate so much more in a quicker and faster way So yeah in this tutorial. That's all I kind of want to show you today We're gonna get into parameters. We're gonna get into return types and that sort of thing. We're gonna get into scope But hey, thanks for watching guys. I hope you enjoyed this and I will see you next time