Transcript
The following content is provided under a Creative Commons license. Your support will help MIT Open Courseware continue to offer high-quality educational resources for free. To make a donation or view additional materials from hundreds of MIT courses, visit MIT Open Courseware at ocw.mit.edu. All right, we've got we've got some good competition here. So, let's let's actually work through it. Okay. So, I'm I have a function called always sunny and it's going to take in two two variables, right? T1 and T2. And I'm calling it with cloudy and cold. Okay. So, when I do my function call, T1 is going to be equal to um cloudy.
These are strings, but uh I'm not going to bother putting the quotes. And T2 is equal to cold. Comma. Okay. So, remember what I said. With a comma, it's a tuple. Without a comma, it's a string. So, T1 is actually going to be a string. And T2 is actually a tuple. Okay. So, that's the first sort of trick to this question. So, I've made my function call and I've assigned T1 and T2 to be those those two values. So, the next line is sun is equal to sunny comma sun. So, sun is going to be this tuple of two strings. The next line is figuring out what first is. So, first is going to be So, I'm looking at my T1 here.
It's a string, right? The fact that I have parentheses doesn't actually make a difference when I'm talking about strings. Like that. So, when I'm indexing into a string, T1 at position zero actually just gives me a C. Cuz it's a string, not a tuple. And T2 at position zero says, "Okay, well, this is a tuple that contains only one element. That element being at position zero. And that element is the string cold. Right? So, this is a tuple. So, I'm taking everything right before the first comma. And that happens to be just the one element that's in there. Okay? So, this is just the string C cold.
And then I'm returning here a tuple. And the tuple I'm returning is sun at position zero. So, that's just sunny. Comma. Just doing what is what's in here. And then first. And first was the string C cold. Okay? So, really the important thing about this ex- example was to make sure that you understand the difference between what a string is and what a tuple is. Okay?