1 00:00:00,000 --> 00:00:01,130 [No audio] 2 00:00:01,131 --> 00:00:05,076 To calculate the average of these grades, we want to see 3 00:00:05,077 --> 00:00:09,946 if a list type has some sort of mean or average 4 00:00:09,947 --> 00:00:14,474 method that allows us to get the average of its values. 5 00:00:14,475 --> 00:00:18,980 For that, we go to check with dir(list). 6 00:00:18,981 --> 00:00:24,538 So list is the name that represents all lists. 7 00:00:24,539 --> 00:00:27,692 So that is a type, and this is an 8 00:00:27,693 --> 00:00:33,240 instance of that type of list type, dir(list). 9 00:00:33,770 --> 00:00:35,932 And let's have a quick look here. 10 00:00:35,933 --> 00:00:38,730 Do we have a mean or average method? 11 00:00:39,630 --> 00:00:40,940 I don't think so. 12 00:00:41,470 --> 00:00:44,912 So there's no method of the list type to 13 00:00:44,913 --> 00:00:49,126 allow us to calculate the average of list values. 14 00:00:49,127 --> 00:00:51,338 However, that doesn't mean there adoesn't exist 15 00:00:51,339 --> 00:00:54,852 A mean method in Python to do that. 16 00:00:54,853 --> 00:00:57,338 mean or average is not a method, 17 00:00:57,339 --> 00:00:59,490 but it can be a function. 18 00:00:59,491 --> 00:01:01,600 You remember the print function. 19 00:01:02,550 --> 00:01:06,462 So print like that, you see that print 20 00:01:06,463 --> 00:01:09,800 doesn't need the dot notation to be used. 21 00:01:09,801 --> 00:01:15,128 Like, for example, the upper method did 22 00:01:15,129 --> 00:01:18,108 need a dot notation because upper is 23 00:01:18,109 --> 00:01:20,920 a method attached to the hello type. 24 00:01:21,530 --> 00:01:23,852 And print is a function. 25 00:01:23,853 --> 00:01:26,236 It's an independent function that 26 00:01:26,237 --> 00:01:28,114 works with many types. 27 00:01:28,115 --> 00:01:30,962 Not only strings, not only integers, floats, 28 00:01:30,963 --> 00:01:33,206 you can print anything with print. 29 00:01:33,207 --> 00:01:37,232 That's why it's not attached to a specific type. 30 00:01:37,233 --> 00:01:38,960 So where do we see a complete 31 00:01:38,961 --> 00:01:42,052 list of functions that we can use? 32 00:01:42,053 --> 00:01:54,300 You can do that using dir(__builtins__). 33 00:01:54,310 --> 00:01:55,609 And that is 34 00:01:55,610 --> 00:01:58,500 [No audio] 35 00:01:58,501 --> 00:02:01,096 a complete list of 36 00:02:01,097 --> 00:02:03,790 what you can use built in functions. 37 00:02:03,791 --> 00:02:05,980 So let me see for a mean function 38 00:02:05,981 --> 00:02:09,564 or an average function. No, it's not there. 39 00:02:09,565 --> 00:02:12,840 Okay, but there is a sum function. 40 00:02:13,450 --> 00:02:17,551 So what we can do is let's say mysum, 41 00:02:17,552 --> 00:02:19,728 don't use sum as a variable name because 42 00:02:19,729 --> 00:02:22,410 you can see that sum is a reserved keyword. 43 00:02:23,070 --> 00:02:28,592 So sum(student_grades) that will give 44 00:02:28,593 --> 00:02:31,600 us the sum of these three numbers. 45 00:02:32,130 --> 00:02:35,108 And then we want to count how 46 00:02:35,109 --> 00:02:38,020 many items there are in that list. 47 00:02:38,021 --> 00:02:40,900 So do we have a count something there? 48 00:02:40,901 --> 00:02:42,020 Maybe not. 49 00:02:42,021 --> 00:02:46,216 Well, I know there's no count method, but we have 50 00:02:46,217 --> 00:02:52,100 this len, which means, you can check what it means. 51 00:02:52,101 --> 00:02:55,066 [Author typing] 52 00:02:55,066 --> 00:02:58,790 So return the number of items in a container. 53 00:02:59,370 --> 00:03:02,642 So a list is also referred to as a container. 54 00:03:02,643 --> 00:03:08,790 Let's say length equals to len(student_grade). 55 00:03:09,610 --> 00:03:13,309 And then finally we can get the mean, which is my 56 00:03:13,310 --> 00:03:22,480 mysum divided by length, and print out the mean. Save, 57 00:03:22,481 --> 00:03:24,766 [No audio] 58 00:03:24,770 --> 00:03:29,040 and that is the mean value of all those three numbers. 59 00:03:29,041 --> 00:03:33,500 [Outro sound]