So, let's go over some of the things that we've learned so far.
So, remember that slicing an indexing works with tuples just like it works with strings,
lists or other kinds of sequences.
So here we have a tuple, Julia,
with a few items, some strings, some integers.
On line two, we print out Julia sub two.
If we want to determine what that prints out,
we first need to determine what kind of operation this is.
So, we see that we're saying Julia sub and
so that should tell us that we're either indexing or slicing.
I don't see a colon here,
so that should tell me that this is indexing.
So, when I print out Julia sub two,
that's going to print out the third item.
Again, the third item because we're zero indexed.
So, the third item is zero,
this is one, this is two and so this should be 1967.
Then we print out Julia sub two through six.
So, in order to determine what that prints out,
I'm going to write the indices on the edges of the items; six.
So, two through six is going to be, two through six,
and so that should be everything from 1967
through actress and that's what this slide should print out.
When we print out the length of Julia then that's going to ask how many items are there.
So I see there's zero, one, two,
three, four, five, six.
Don't get fooled by the comma here,
it's actually part of the string not part of
the tuple definition and so that's going to say that there are one,
two, three, four, five, six, seven items.
If the last index is six,
then because there's a zero here,
then that means that the length is seven.
Then here we have a complicated concatenation operation.
So, first we take Julia sub from the beginning through item
three and so that's going to be Julia Roberts 1967.
So let me write that out. Julia Roberts 1967.
Then we concatenate to the string Eat Pray Love in 2010.
So, Eat, Pray,
Love and 2010 and then we add Julia from index five on.
So that's going to be everything from actress on.
So that's Actress
and Atlanta, Georgia.
I just add commas between these and this gives us a tuple back.
So, this is what I expect to print when we run this code.
Let's test our hypotheses.
Okay, so I see that line two does indeed print out 1967,
line three does in fact print out everything from 1967 through actress,
line five does in fact print out
seven and line eight does in fact print out this list that we specified.
So, let's go over some questions related to slicing and indexing.
So first if we ask,
what's printed out by the following statement?
So, the string S is Python rocks and we print out S from index 3-8.
So, in order to determine what actually gets printed out,
then I'm going to first find out where index three is,
so this is zero, one, two, three.
So, what that means is that because we include index three,
I'm going to draw a line right here and then we print out that through eight, four,
five, six, seven, eight but we don't include index eight because
we move kind of all of these dots to the left and so what that
means is that we're going to get everything from here to here.
So, we should get hon space r or item
C. Okay, next question.
So here we have a list that has a mix of some integers,
some strings and some actual other lists as items.
So what we're asking is what's printed by the following statement.
So we create this list and we print out a list sub four colon.
So in order to figure that out,
and I'm going to first find index four,
so we have zero,
one, two, three, four.
So, index four contains
this empty list and because we don't have anything after the colon,
then we're saying we want everything from index four on
and so we can draw a kind of a line here and we know that
it's going to contain everything from this empty list to
3.14 to false and so I expect the answer would be A.
We can see that answer A here was the correct answer.
Okay. So now we have a question asking us to create
a new list using the ninth through 12th items.
So, four items in all of new list and assign it to the variable sublist.
The first thing I'm going to do in order to answer this question is I'm going to say
sublist equals and then I know I'm going to be slicing on new list.
So, I'm going to say sublist equals new list sub.
If we want the ninth item then we actually have to use index eight.
So, I'm going to say index eight and because I want a subset then I want to slice,
so I use the colon.
I went through the 12th item.
So, if we include index eight, nine, 10,
11, then that's going to give us four items.
So, what I want to say is,
I went through but not including index 12 because that's actually the 13th item,
because again, Python is zero indexed.
So if I say sublist equals new list from indices eight through 12 and run it,
then I get the correct answer.
That's all for now, until next time.