Skip to playerSkip to main contentSkip to footer
  • 5/21/2025
The return keyword in Python serves to exit a function and optionally return a value to the caller. When a return statement is encountered within a function, the function's execution is immediately terminated, and the specified value is passed back to the part of the code that called the function. If no value is explicitly specified, return will return None by default.
Transcript
00:00I was summarized in the second lecture in function definition.
00:03I had to say that function should do one thing and one thing only.
00:06This doesn't mean that function cannot do more than one thing.
00:10You are making a game.
00:12So, in one function, you can define a hero, villain, weapon, life, etc.
00:16But it is standard practice.
00:19It is normal standard practice that you need to do one thing.
00:24Another important thing is that a function must return something.
00:28What does return mean?
00:30Return means that function should give you a value to a function.
00:37So, you can go back to the left and the left and the left and the left and the left and the left and left.
00:46Now, you can say that this function has already returned.
00:50Well, let's see.
00:52Receipt is default value.
00:57I will execute.
00:59And here you can show the value.
01:01Return key word.
01:03Remove it.
01:05And value show it.
01:07Basically, value show it.
01:11Return is not true.
01:13Return is not true.
01:15Return is true.
01:17Return is true.
01:19The value is true.
01:21The value is true.
01:23It would be true.
01:25If you could take your father and mother or mother or elder, you can get money to your money in your pocket money.
01:31And you can give your money to my pocket money.
01:34So, if you will show the value of pocket money in your pocket money in your pocket money.
01:37it's a $10,000, or $10,000.
01:41So that value you can use,
01:43which means you can't see.
01:45For example, you can use this when you do shopping,
01:49you can't buy this.
01:50You can't buy this, you just growth,
01:51you can't buy this,
01:52so that value you can print it.
01:55If you value you can use it,
01:58then you can use it.
01:59It's called return.
02:00If you'll start a return,
02:01when you go, let's say,
02:03a toy, if you look at it,
02:04it's a return when you come up.
02:05It's a return.
02:07This means that you can use this
02:11For example, if I say this
02:13Receipt is equal to x
02:16This means that I will print it
02:19And then I will print it
02:22Then I will say none
02:24Why not?
02:25Because I will say that
02:27I will not give it
02:30Just give it
02:32If I say this
02:39Let's say x plus 2
02:41Let's say x plus 2
02:42If I can do it
02:44I can do it
02:45Error
02:46None type
02:47Why?
02:48Return
02:49Make sense?
02:52If you understand
02:54You can go to the store
02:56And you can see the store
02:58You can see the store
03:00This is basically print statement
03:04That you can show
03:05However, if you want that
03:07You can use it
03:09That you can return
03:10Now you can imagine
03:12Imagine
03:14We have our continue owner
03:16Continue owner
03:17We have to say
03:18Income tax
03:19We have to say
03:20Which amount
03:21That you can do
03:23That you can do
03:24That you can do
03:25Two dollars
03:26Two dollars
03:27That you can do
03:28That you can do
03:29Now we can say
03:30That you can do
03:31That you can do
03:32That you can do
03:33That you can do
03:34How much amount
03:35Is there
03:36What amount
03:37Is there
03:38How much amount
03:39So
03:40For example
03:41If I can say
03:42Let's say
03:43Let's say
03:44Let's say
03:45Let's say
03:46X
03:47Here I can say
03:48Text
03:49And I can do
03:50Text
03:51Print
03:52Now
03:53Text
03:54Sorry
03:55Print
03:56She can do
03:57Amount
03:58And here you can say tax is equal to 2, so I want to print amount minus tax.
04:07However, if I perform this function, then the result is error.
04:11That's the reason, again, when the recipient function has nothing to return,
04:15so I can't remove tax.
04:18So in order for me to use this thing, use this value further,
04:23I will return to this value.
04:26So here I will say return.
04:30And what return is the amount.
04:34Right?
04:36So basically, the value will return,
04:40it will be amount.
04:43Because this function will return amount,
04:47then I can assign someone to someone.
04:50And then I can do operation.
04:52So if I execute it,
04:54this is 8.
04:55Why?
04:56Because amount is return,
04:58then I can assign amount.
05:00Then I have text to $.
05:02And the amount of tax is removed.
05:04So this is 8.
05:06Right?
05:07So return basically,
05:09you give value to it,
05:10so that you can further use it.
05:12If you don't return,
05:14then by default function,
05:15none return will return.
05:18Okay?
05:19So here you can print function.
05:22This function will show you.
05:23Basically,
05:24it will show you.
05:25This is the window shopping.
05:26You can use it.
05:28You can use it.
05:29You can assign it.
05:30You can assign it.
05:31However,
05:32if you have this value to assign it.
05:34You can return it.
05:36You can return it.
05:37You can return it.
05:38So you can assign it.
05:39Okay.
05:40Okay.
05:43So,
05:44I'll close this lecture.

Recommended