[No audio]
In this video, you will
become more familiar with lists.
So previously we stored three float data types in a list.
But you can store any type of object, not only
floats. So we can store an integer such as 9.
You can store a string such as Hello.
You can even store lists inside a list.
You just write the square brackets and
then enter the items of that list.
So still, this list has three items.
This integer, this string, and this list.
And of course, you can print out that list
by pointing to the variable associated with the list.
[No audio]
And that's the output that we get.
Now, Math operations with lists,
what does list support?
Well, not much really.
You can do
[No audio]
multiplications with an integer such as 2
or 3, and let's see what's going to happen.
So I'm going to print out that expression directly
here instead of putting that in a variable.
So whatever you prefer, you can create a new
variable, store that in the variable, and then place
the variable in the print function, or directly place
this expression in the print function.
Both will work.
So if you run that, you're going to get this
output. So that the same list repeated three times.
If this was plus, this is not supported because Python doesn't
know what to do with a list and an integer.
So it gives you an error, TypeError only can concatenate
lists to lists, so it can concatenate lists to lists.
So if you do student_grades plus
student_grades, that will also work.
So run that and you get this result.
So the list repeated two times, which
is the equivalent of that times two.
So again, we're going to get
the same results, here and there.
Lastly, there's also a way to auto generate
lists of integers that have a certain order.
Let's say you want to have a
list from 1 to 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
How can we do that?
Well, of course one way is to write that down, but there
is a better way, and that is to use a range.
range is another type of object.
Just like we have lists, integers, we also have ranges.
So range 0 and 11.
And let's run student_grades to see what
this variable has now as a value.
So run that and this is a range object.
So not much to see yet, but if
you convert this into a list and run again,
[No audio]
lastly we're going to get that output.
So 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
So now student_grades is a list object
and this list keyword here is a class.
So it represents the list data type, and it is
used here to convert a range data type into a
list data type, because a range displays simply like this.
So this is not very beneficial to see.
The output is not so clear, so we
convert it into a list data type.
And so how does it work?
Well, it starts from 0 up to the
number before this number, which is 10.
So 0 to 10.
That's why we have 0 to 10.
Of course, you can have anything here.
So 1 to 8, I would have to
write 9 to get 1 to 8,
so it'll list 1 to 8.
You can also have another argument here, two, and
let's see what that changes in the output.
[No audio]
So we get these results, that 2 is the step.
So 1, 3, 5, 7, it means that you start from 1
and then you move by a step of 2.
So 1 plus 2, you have 3.
3 plus 2, you have 5.
5 plus 2, you have 7.
7 plus 2, you have 9,
but 9 is not included in the range.
The range is up to 8, so
the list will end up at 7.
Of course, you can have any steps here,
like 3, and you'll get different results.
So that was some more advanced
information about lists and also ranges.
With that, I thank you and I'll
talk to you in the next video. See you there.