1 00:00:00,000 --> 00:00:03,396 Something to point out is that when your 2 00:00:03,397 --> 00:00:09,550 function doesn't have a return statement, save, execute, 3 00:00:10,290 --> 00:00:13,840 it implicitly returns a None object. 4 00:00:14,530 --> 00:00:16,484 None is a specific object 5 00:00:16,485 --> 00:00:18,800 in Python, which means nothing. 6 00:00:19,570 --> 00:00:20,948 It's not an integer, it's not 7 00:00:20,949 --> 00:00:22,282 a float, it's not a string. 8 00:00:22,283 --> 00:00:23,530 It's just None. 9 00:00:23,531 --> 00:00:24,660 It means nothing. 10 00:00:24,661 --> 00:00:27,292 So Python, what it does is, if 11 00:00:27,293 --> 00:00:29,548 it doesn't find the return statement on 12 00:00:29,549 --> 00:00:33,050 the background, it does this return None. 13 00:00:33,051 --> 00:00:37,762 So if you execute that oops, an indentation error. 14 00:00:37,763 --> 00:00:41,328 That's a good thing. So you see that all this block here 15 00:00:41,329 --> 00:00:44,550 has to be the same level of indentation. 16 00:00:44,551 --> 00:00:46,848 If you indented four lines here, you have 17 00:00:46,849 --> 00:00:48,960 to indent four lines in here, too. 18 00:00:48,961 --> 00:00:51,790 So indentation has to be consistent. 19 00:00:53,010 --> 00:00:54,880 That looks right. 20 00:00:56,130 --> 00:01:01,280 So we got the same output None here and None there. 21 00:01:01,890 --> 00:01:04,974 Some people do this mistake. 22 00:01:04,975 --> 00:01:08,494 Instead of returning, they use print. 23 00:01:08,495 --> 00:01:10,846 Instead of using return, they use a print 24 00:01:10,847 --> 00:01:18,570 function, the_mean, which works half the way. 25 00:01:18,571 --> 00:01:21,320 So it still returns the value, 26 00:01:22,250 --> 00:01:24,450 and it also returns None. 27 00:01:24,451 --> 00:01:27,852 So what's going on here is that when you call 28 00:01:27,853 --> 00:01:31,638 the function here, Python will execute all these lines. 29 00:01:31,639 --> 00:01:33,790 So it calculates the_mean. 30 00:01:33,791 --> 00:01:35,456 Then it goes to the next line. 31 00:01:35,457 --> 00:01:38,688 So line by line, it will print the_mean. 32 00:01:38,689 --> 00:01:41,664 So it will print out the_mean in here, 33 00:01:41,665 --> 00:01:44,746 and then it will look for a return statement. 34 00:01:44,747 --> 00:01:48,154 It doesn't find it, so it will return None. 35 00:01:48,155 --> 00:01:52,420 The problem with this is that if you try to do 36 00:01:52,421 --> 00:01:59,960 some other operations with your mean value, let's say mymean 37 00:01:59,961 --> 00:02:07,320 is equal to the mean function 0, 3, and 4, okay? 38 00:02:08,330 --> 00:02:13,560 And I want to print out mymean + 10. 39 00:02:14,090 --> 00:02:16,732 So I would expect that this would give me the 40 00:02:16,733 --> 00:02:21,308 value of, 7 is the sum divided by three. 41 00:02:21,309 --> 00:02:25,244 So 2 point something plus 10, 12 point something. 42 00:02:25,245 --> 00:02:27,640 But let's see what this will give me. 43 00:02:27,641 --> 00:02:29,600 [No audio] 44 00:02:29,610 --> 00:02:32,362 So this will give me a TypeError 45 00:02:32,363 --> 00:02:37,242 instead. It tried to add the none type, which is None. 46 00:02:37,243 --> 00:02:38,660 So this is a none type. 47 00:02:38,661 --> 00:02:40,500 That's the type of this value. 48 00:02:40,501 --> 00:02:43,732 It's trying to add that to ten. 49 00:02:43,733 --> 00:02:46,766 So mymean is None, because it returns none. 50 00:02:46,767 --> 00:02:50,296 And the interpreter will try to add up that to 10. 51 00:02:50,297 --> 00:02:51,512 That's not possible. 52 00:02:51,513 --> 00:02:54,850 So that's why you shouldn't use print. 53 00:02:55,450 --> 00:02:59,644 If I replace that with return instead, remove the 54 00:02:59,645 --> 00:03:05,530 parentheses, save, execute, that will give me 12.3. 55 00:03:05,531 --> 00:03:07,996 That is the average plus ten. 56 00:03:07,997 --> 00:03:10,214 However, this doesn't mean you cannot 57 00:03:10,215 --> 00:03:12,150 use print in your functions. 58 00:03:12,151 --> 00:03:13,820 You can actually do that. 59 00:03:14,510 --> 00:03:17,229 Let's say you just want to print some information. 60 00:03:17,230 --> 00:03:19,633 [Author typing] 61 00:03:19,633 --> 00:03:23,360 started, Function started!, and execute that. 62 00:03:24,690 --> 00:03:28,548 So you get the output of print in 63 00:03:28,549 --> 00:03:32,320 here, and then Python returns the mean. 64 00:03:33,410 --> 00:03:35,332 So you get the mean, you store it 65 00:03:35,333 --> 00:03:37,828 in here, the output of your function. 66 00:03:37,829 --> 00:03:40,036 But the value of the function is 67 00:03:40,037 --> 00:03:43,730 always what you return in here. 68 00:03:43,731 --> 00:03:45,163 So if you see that it, 69 00:03:45,164 --> 00:03:49,166 [Author typing] 70 00:03:49,167 --> 00:03:52,156 so always use return in your 71 00:03:52,157 --> 00:03:56,120 functions, unless you have a very special reason to do so. 72 00:03:56,121 --> 00:03:59,666 [Outro sound]