Instructor: Now tuples, like I said,
are quite similar to lists.
So if I wanted to, I can say new tuple
and use my tuple and then slice that tuple.
So for example, if I do 1, 2 like this
and print new_tuple,
I'm going to get 2 comma.
Hmm. Why is that?
Well, we start at zero one and end at two.
If I did four here and click run,
I get 2, 3, 4.
It's still a tuple.
But you have to remember that a tuple
that only has a single item tends to have
this little comma at the end, but it's still a tuple.
And just like a list, I can assign different things.
For example, I can say x equals to
my_tuple[0].
And then I can say, y equals my_tuple[1]
and x and y will equal 1 and 2.
But a short form of doing this, again, similar to lists
is to say, Hey, I want
x, y, z
you know what, other to be the values assigned
from the tuple so that if I do x here and I run,
I get 1.
If I do z and I run,
I get 3.
What if I do other?
And if I click run, I get four and five as a list.
All right.
If your head doesn't hurt by now, don't worry.
I have some good news.
Luckily for us, a tuple has only two methods
that we care about.
count and index.
How nice is that?
So nice and simple.
Guess what these mean?
So let's go back to my_tuple
and now try these out.
If I go my_tuple.count, well it's going to count the value.
So if we wanna count how many fives occur in the tuple
I get one.
If I had another five in the tuple, I get two.
What about index?
What's the index of five?
Well, the index of 5 is four
because zero, one, two, three, four.
The first value that it finds
it's going to return the index of.
And then finally, we can also do length, right?
We can use this built in function to run length
and it's going to tell us that,
yep, it's has a length of six.
Awesome, there it is.
We're flying through them now.
This is our third data structure.
Remember, there's simply lists that are immutable.
I'll see you in the next one.
Bye bye.