So far you have learned some of the main data types available in platform that are not he didn't truths
about integers or floats.
But there may be a few things you need to know about sequences such as lease and tuples and strings
as well.
So that's what I'll explain in this lecture.
First let's talk about indexing streams support indexing.
Just like some tables.
So let me generate a quick least using a list function and the range function as well.
So I'll store my list in my file this valuable and I write the list function.
So those functions generate a list object then to the Lisp function.
I'll pass a range function and then to the range function I'll pass a range of numbers starting from
2000 and ending at 2020 with the step of two.
And here is the list.
Now I'll quickly teach you how to access certain parts of the list.
So first we're going to access a single item of values that we are going to access a certain slice of
the list.
Then all of the first three items then all the items are for the second item and only the last two items
of the list to understand them and perform those actions you should already know how the items are the
least indexed.
So each item of the list is hiding a certain index underneath indexes start from zero and increment
by 1.
So the first line item has an index of zero.
The second item as an index of one and so on.
Now let's start by accessing an item of the list.
Let's say I want the third item because the counting starts from zero.
Index off of the third item is to see syntax is this.
We write the variable name that contains a list and then we write the index inside square brackets.
Now let's see it by four returns.
The third item of the list the fourth element you'd need an index or three.
And so one know sometimes you might need to access more than one element of the list.
Let's say you want all that part of the least that's towards 2002 and 2010 including 2010 to extract
such a slice from families.
You need to know the index of the lower and upper Bollen numbers of the slice that we want in this case.
They are index 1 and 5.
The syntax is this.
So the name of the list the square brackets the index of the first number column an index of the number
or for the upper bound number or the slice.
So why is the number after the upper bar number you'd ask.
Well the answer is that the slices and oranges are upper bound exclusive meaning that the number identified
by the last index is not included in this list.
So if you write five year of slice you will not include the item with index 5.
Therefore we tried six to include the the number with ex-wife and we have our slice.
Sometimes you might want to access only the first three elements or at least for example and you could
do that using zero has a lower bound index and three as upper one however.
A quicker way to do that is to just use the last index without explicitly writing the number 0.
So it's just like saying OK Python give me everything before three including three if you want us a
slice consisting of all the items after the second night of the list you would need to write two and
a column inside the square brackets.
So this is like OK Python.
Now give me everything of the two.
And if you want the last two items of the least you could count like 0 1 2 3 4 5 6 7 8 and tell them
to give you everything right including 8.
But hey don't you find this a bit stupid.
Counting from the start when you won the last two items.
Sure.
That's a bit Silverlink That's why a second indexing convention exists along.
The first one starts at zero and incrementing by 1.
So this second indexing I'm talking about starts at minus 1.
The upper bound of the list and decreases by 1.
So minus one for the first item starting from the upper bound minus 2 for the second item.
And so on.
So if we want the last two items of the list we don't need to count.
We just can't tell a python.
Give me everything up to minus two including minus two and if you want a slice that excludes the last
two items you could tell by phone hey give me everything before minus two including minus two.
That's it.
Now these were all loose slicing operations.
You could apply the exact same operations to streaks so.
So if you have a string of let's say something and I'm going to store it in a variable the same indexing
conventions applied to things.
So if you want the fourth character you're right the variable than the index inside those square brackets
which is three I'll let you practice the rest of the slicing operations with strings on your own pace.
Now towboats do not escape from the circles either.
So we have this table and I'm going to extract the last item only.
And by phone gives you everything golfer minus on including minus one.
I hope that was clear.
That's what I wanted to teach you about slicing leasts strings and total's.