Akansha Yadav shows how the return keyword works in Python functions. A function that squares a number returns the computed value to the caller, while a function without return yields nothing. Return gives you the value directly, no print statement needed.
Chapters
Ladies and gentlemen, another concept in the function is that return value. So what is the return value in Python function? Function in which you wanted to return any value— suppose you are doing any calculation within the function and you want that calculated value to be returned. So what you will do is you will use the return keyword. It is return is a keyword in Python, so you will use that thing to return it. So let's suppose I'm saying def calculate_result. I have written def calculate_result in which, in which I am doing calculation and result. So let's suppose, let's make it bit meaningful. I'm going to square square of any number. I'm— let's say, so what I will do is I will say, okay, def square of number, then following up with what you wanted to do. I wanted to return some value with the— in the function. So square is basically using this. So I'm going to call my function saying square of, let's say, 4. So my function is def square, is the function's name, number is the parameter, and I'm expecting it to return some value to us. So if I have not written return, what will happen? We are not getting any output, right? So that is why the return value comes in. Picture. You're not required to write print or something like that. It will just directly return that particular value to us. So that is how the return value works. Here it takes a number as a parameter and returns its square. That's it. That is how return value works.