 Okay, welcome to Python for Java coders. This is lesson nine. I've been at it for two hours now and this is the last one I'm gonna do today for sure. So in this lesson, we're gonna take a look at how functions or methods, whatever you wanna call them, work in Java versus in Python. Okay, so let's get started. Again, Java, you need class structure, Python, you do not. So we're going to make a method called printpy. So in this case, I am calling the method. Again, notice, camel casing versus snake casing. So then if I scroll down here, you'll see I've got this method, public static void printpy, system out printlin 3.14159. So in Python, the equivalent code would be the following. Def means define printpy, parentheses, colon, because we always use colons. And after colon, you're always gonna see an indent. So you can see which is part of the function, which is part is not. And print 3.14159. And it's a number, so I don't need to put it in quotation marks, although I could. So let's go ahead and run this and let's see if it works. Okay, very interesting. Okay, at this point, you think, wow, that's kinda weird. The printpy method's been defined. I've called it, but it says that it's not defined. So here's a little bit of a difference. In Python, you've got to define your functions first before you can call them. Now in Java, I guess because it's pre-compiled into bytecode, it reads the whole thing and it knows that you're going to have this method eventually. But Python's an interpreted language, so you see little things like that, little differences pop up. So let's go ahead and run that, make sure it's working. Okay, very good. Now notice in Java, I had to declare this as a static method because it's not attached to an object. Python, I didn't have to do that. I had to declare the return type, avoid in this case because there's no return, didn't have to do that. And here's the same thing, there's nothing in the parentheses, so I didn't have to put anything there. Let's move on. Next function is print. Let's see, I'll put this, oops, old habits. Call functions and up here I'll call this define functions and functions are methods that you can use interchangeably. So the next one is print double two. So let's go find print double. Okay, so here's our definition of our method. So again, don't worry about public, don't worry about static, don't worry about void, don't worry about anything like that. Just go ahead and print double. And now in this case, it's using X because we are sending a value. Of course, here we had to declare it as an int, here we don't. And then I can go print X times two. Okay, so I'm gonna go ahead and run that. And what did I do wrong? Print double, ah, forgot the def. And go ahead and run that. And there is the answer, which matches up with what we have here. Now here's something interesting, two interesting things about Python. I can send anything to that because there is no strict typing. If I wanna send, you know, my name, my nickname will say Tokyo EdTech, I can send that. Let's go ahead and run that. And this is another interesting Python thing I didn't talk about in the string video, but if you multiply a string, it just prints it out twice. Now how cool is that? That comes in handy in a lot of situations. Okay, so if I'm gonna put that back to a, now if I, again, if I put that as a string, I wanna see two, two. But the, what I wanna see is two, times two is four. Interesting. Next one, okay, is getpy. Alrighty, this is an interesting one. So, let's say def getpy, again look at the snake casing. And this is just going to return 3.14159. Again, I don't have to, where's that print getpy? I don't have to declare it static, don't have to say I'm returning a double. I just do it. Okay, so here I'm gonna go ahead and to match this, I'm gonna say py equals getpy and print. So I did not need to declare that at all. Cause it knows that I'm returning a double. Okay, this is gonna be a double now. If I had to return a string, it would be a string. Next up, greatest equals getgreatest. Okay, so this is where it's getting a little more interesting. Getgreatest, and let's go find the definition down here. Oh, I should have done get.one, missed that one. Let's, yeah, get.one, let's go ahead and do that one. Get double. So in these functions, in these methods, here I was not sending a value and not returning a value. Here I was sending a value and not returning a value. Here I was not sending a value but returning a value. And in this last example, I'm gonna be sending a value and returning a value. So get double. So I think I used x, get double, yeah, x. Again, I don't have to declare it as an int. And I'm just gonna return x times two. Then when I call it down here, I'll say y equals get double, four. And then we'll go ahead and print y. That should give us eight. Okay, so far so good. And our next one is getgreatest. Okay, so I'm gonna go ahead and define that. Define getgreatest. And this is just an example to show you that we can send more than one value. Again, in Java, you need to declare it, and by that I need you not, colon. And then if, again, the parentheses are optional. You can have them, you do not have them. Say return x, else return y. Again, parallel structure, but you don't need the braces or the semi-valence. I'm gonna go down to here and actually try and call this method a little bit. So I'm gonna say greatest equals getgreatest. We've got 42 and 16. And then go ahead and print greatest. And of course it should print 42. The answer to life, the universe, and everything. And the last one. Okay, so in this case, we're actually gonna be returning a Boolean instead. And again, the function definition goes before the function call. So I'm gonna say define is even using my snake casing, x. And if percent, oops, x percent two equals zero. Again, two equal signs. Return true, true is capitalized. Else, oops, forgot the colon. Return false capital letters. And in my calling part here, I'm going to go ahead and make a little if statement. So if is even, 42 colon. And again, I didn't need these extra parentheses. I could have just done this. Whatever you think makes it look nicer. Print even. And otherwise, of course, we've got two options. Print, oops, odd's not odd. Let's go ahead and run that. And we should see even at the bottom. It takes a little bit of time sometimes. So we're dealing with a remote server. So maybe they get busy. And it is even. Let's go ahead and just try a different number. Let's try 43 just to test it and make sure our code's working correctly. And odd, there we go. Okay, I'm gonna put that back to 42 though, because that's a better number. So you can see here with the difference between a couple of differences between Java and Python. Python, you need to declare the function ahead of time before you call it. We don't need to declare whether it's static or non-static. It's done a different way in Python. We don't need to declare whether the return type is void or double or int or boolean. It's just automatic. We don't have to declare the values that we send the type as integers or whatever. We just send them and hope that we send the right thing. Now the advantage of the Java way of doing it is that when you compile it, it catches a lot of errors. Okay, so for example, if I had done this, it would catch that error. It would say, oh, you're trying to send a string even though it's looking for an integer and it won't let you run that program. It won't let you run it until you correct that issue. That's the advantage of doing it the Java way. It's also much, much faster. The Java code is faster than Python code, generally speaking. So it's an advantage, but as a programmer, you have to take care of a few more details. So you have to think about what's the trade-off for you as a coder or for you as trying to solve a particular problem. And yeah, so when you're declaring a function or a method here, you say public. You have to declare if it's public or private. Python, it's actually very, very different. Java's really strict with that. I'll just show you a quick example to give you an idea. If I do private here, the equivalent in Python I think is you do one underscore before and after. I can't remember if it's private or if it's two underscores, one's protected. I forget the actual rule on that. I should have looked it up before I did the video. I'm sorry, but anyway, you don't actually use public and private. You use underscores to indicate whether it's public, private, or protected. And even if it is private, you can just ignore it, which is kind of cool. Which is I think kind of cool, but it's probably bad programming practice for large programs, especially. So there you have it. That is lesson nine. I have done this in about two hours, this entire series. And I'm gonna stop there. And because that's all I have for you for this particular thing, hopefully that will give you a pretty good idea how to at least get you started on your Python journey if you have already gone through at least part of your Java journey, which has nicer alliteration. So yeah, thanks for watching. Subscribe if you like what you see and keep on coding. Take care.