1 00:00:00,790 --> 00:00:03,190 The following content is provided under a Creative 2 00:00:03,190 --> 00:00:04,730 Commons license. 3 00:00:04,730 --> 00:00:07,030 Your support will help MIT OpenCourseWare 4 00:00:07,030 --> 00:00:11,390 continue to offer high quality educational resources for free. 5 00:00:11,390 --> 00:00:13,990 To make a donation or view additional materials 6 00:00:13,990 --> 00:00:17,880 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,880 --> 00:00:18,840 at ocw.mit.edu. 8 00:00:22,630 --> 00:00:25,570 PROFESSOR: All right, we've got some good competition here. 9 00:00:25,570 --> 00:00:27,560 So let's actually work through it. 10 00:00:34,220 --> 00:00:37,070 So I have a function called always sunny 11 00:00:37,070 --> 00:00:42,050 and it's going to take in two variables right, t1 and t2. 12 00:00:42,050 --> 00:00:47,810 And I'm calling it with cloudy and cold. 13 00:00:47,810 --> 00:00:51,770 So when I do my function call, t1 14 00:00:51,770 --> 00:00:56,465 is going to be equal to cloudy. 15 00:00:59,140 --> 00:01:01,810 These are strings but I'm not going 16 00:01:01,810 --> 00:01:03,910 to bother putting the quotes. 17 00:01:03,910 --> 00:01:10,840 And t2 is equal to cold comma. 18 00:01:10,840 --> 00:01:15,180 So remember what I said, with a comma it's a tuple, 19 00:01:15,180 --> 00:01:17,280 without a comma it's a string. 20 00:01:17,280 --> 00:01:20,930 So t1 is actually going to be a string. 21 00:01:20,930 --> 00:01:23,090 And t2 is actually a tuple. 22 00:01:23,090 --> 00:01:23,835 OK. 23 00:01:23,835 --> 00:01:25,960 So that's the first sort of trick to this question. 24 00:01:29,230 --> 00:01:32,040 So I've made my function call and I've assigned t1 and t2 25 00:01:32,040 --> 00:01:35,970 to be those two values. 26 00:01:35,970 --> 00:01:39,910 So the next line is sun is equal to sunny comma sun. 27 00:01:39,910 --> 00:01:42,175 So sun is going to be this tuple of two strings. 28 00:01:44,820 --> 00:01:50,250 The next line is figuring out what first is. 29 00:01:50,250 --> 00:01:57,350 So first is going to be-- so I'm looking at my t1 here, 30 00:01:57,350 --> 00:01:58,939 it's a string. 31 00:01:58,939 --> 00:02:00,980 The fact that I have parentheses doesn't actually 32 00:02:00,980 --> 00:02:05,801 make a difference when I'm talking about strings. 33 00:02:05,801 --> 00:02:06,300 Like that. 34 00:02:09,229 --> 00:02:13,550 So when I'm indexing into a string, t1 at position 0 35 00:02:13,550 --> 00:02:17,070 actually just gives me a C because it's 36 00:02:17,070 --> 00:02:18,050 a string not a tuple. 37 00:02:22,240 --> 00:02:26,200 And t2 up position zero says, OK well, this 38 00:02:26,200 --> 00:02:28,900 is a tuple that contains only one element. 39 00:02:28,900 --> 00:02:31,870 That element being at position 0, 40 00:02:31,870 --> 00:02:34,150 and that element is the string, cold. 41 00:02:37,670 --> 00:02:39,090 So this is a tuple. 42 00:02:39,090 --> 00:02:42,861 So I'm taking everything right before the first comma. 43 00:02:42,861 --> 00:02:45,360 And that happens to be just the one element that's in there. 44 00:02:48,150 --> 00:02:50,160 So this is just the string C cold. 45 00:02:53,780 --> 00:02:57,730 And then I'm returning here a tuple. 46 00:02:57,730 --> 00:03:01,290 And the tuple I'm returning is sun at position 0, 47 00:03:01,290 --> 00:03:07,520 so that's just sunny comma. 48 00:03:07,520 --> 00:03:09,590 Just doing what's in here. 49 00:03:09,590 --> 00:03:13,574 And then first, and first was this string, C cold. 50 00:03:16,960 --> 00:03:20,291 So really the important thing about this example 51 00:03:20,291 --> 00:03:21,790 was to make sure that you understand 52 00:03:21,790 --> 00:03:26,610 the difference between what a string is and what a tuple is.