Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,720 --> 00:00:11,650
Something to point out is that when your function doesn't have a return statement, save, execute.
1
2
00:00:11,670 --> 00:00:14,580
it implicitly returns a None object.
2
3
00:00:14,610 --> 00:00:19,800
None is a specific object in Python which means nothing.
3
4
00:00:19,800 --> 00:00:20,630
It's not an integer.
4
5
00:00:20,640 --> 00:00:21,440
It's not a float.
5
6
00:00:21,450 --> 00:00:22,320
It's not a string.
6
7
00:00:22,320 --> 00:00:24,360
It's just None, it means nothing.
7
8
00:00:24,930 --> 00:00:31,910
So Python what it does is if it doesn't find the return statement on the background it does this:
8
9
00:00:31,920 --> 00:00:32,370
return None.
9
10
00:00:33,330 --> 00:00:37,640
So if you execute that, ups an indentation error.
10
11
00:00:37,890 --> 00:00:38,700
That's a good thing.
11
12
00:00:38,700 --> 00:00:46,480
So you see that all this block here has to be the same level of indentation, if indented four lines here,
12
13
00:00:46,500 --> 00:00:49,110
you have to indent for lines in here too.
13
14
00:00:49,110 --> 00:00:52,610
So indentation has to be consistent.
14
15
00:00:53,160 --> 00:00:54,990
That looks all right.
15
16
00:00:56,370 --> 00:01:02,010
So we got the same outputs, None here and None there.
16
17
00:01:02,100 --> 00:01:07,380
Some people do this mistake instead of returning, they do...
17
18
00:01:07,380 --> 00:01:12,880
They use print instead of using return they use a print function.
18
19
00:01:13,440 --> 00:01:18,060
The mean which works half the way.
19
20
00:01:18,840 --> 00:01:21,760
So it still returns the value.
20
21
00:01:22,500 --> 00:01:24,650
And it also returns None.
21
22
00:01:24,660 --> 00:01:31,650
So what's going on here is that when you call the function here Python will execute all these lines
22
23
00:01:31,650 --> 00:01:33,680
so it calculates the mean.
23
24
00:01:33,960 --> 00:01:38,540
Then it goes to the next line so line by line it will print the mean.
24
25
00:01:38,820 --> 00:01:44,860
So it will print out the mean in here and then it will look for a return statement.
25
26
00:01:44,940 --> 00:01:48,260
It doesn't find it so it will return None.
26
27
00:01:48,270 --> 00:01:57,180
The problem with this is that if you try to do some other operations with your mean value let's say
27
28
00:01:59,220 --> 00:02:06,390
my mean is equal to the mean function 0, 3, and 4.
28
29
00:02:06,670 --> 00:02:08,030
OK.
29
30
00:02:08,680 --> 00:02:14,310
And I want to print out my mean plus 10.
30
31
00:02:14,310 --> 00:02:21,410
So I would expect that this would give me the value of 7 is the sum divided by 3.
31
32
00:02:21,500 --> 00:02:27,360
So two point something plus ten, twelve point something,
but let's see what this will give me.
32
33
00:02:29,990 --> 00:02:32,870
So this will give me a type error instead.
33
34
00:02:33,030 --> 00:02:37,270
It's tried to add the None type which is None.
34
35
00:02:37,280 --> 00:02:38,730
So this is a None type.
35
36
00:02:38,760 --> 00:02:43,870
That's the type of this value. It's trying to add that to 10.
36
37
00:02:43,910 --> 00:02:49,190
So my mean is None because it's returns None, and the interpreter will try to add up
37
38
00:02:49,190 --> 00:02:50,280
that to 10.
38
39
00:02:50,450 --> 00:02:51,410
That's not possible.
39
40
00:02:51,530 --> 00:02:55,580
So that's why you shouldn't use print.
40
41
00:02:55,700 --> 00:03:04,040
If I replace that with return instead, remove the parentheses, save, execute, that will give me
41
42
00:03:04,040 --> 00:03:05,680
12.3.
42
43
00:03:05,750 --> 00:03:08,120
That is the average plus 10.
43
44
00:03:08,150 --> 00:03:12,140
However this doesn't mean you can not use print in your functions.
44
45
00:03:12,230 --> 00:03:14,460
You can actually do that.
45
46
00:03:14,720 --> 00:03:17,210
Let's say you just wants to print some information.
46
47
00:03:19,550 --> 00:03:23,080
Started, functions started and execute that.
47
48
00:03:24,890 --> 00:03:35,210
So you get the output of print in here, and then Python returns the mean, so you get the mean,
48
49
00:03:35,270 --> 00:03:36,850
you store it in here, the output
49
50
00:03:36,860 --> 00:03:43,870
of your function, but the value of the function is always what's you return in here.
50
51
00:03:43,940 --> 00:03:44,990
So if you see that.
51
52
00:03:49,260 --> 00:03:55,800
So always use return in your functions unless you have a very special reason to do so.
4782
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.