Many reasons exist to store a set of numbers.
For example, you will need to keep track of the positions of each character in a game, and you might
want to keep track of a player's high scores as well.
In data visualizations you will almost always work with a sets of numbers such as temperatures, distances,
population size or latitude, longitude, values, among other types of numerical sets.
So lists are ideal for storing sets of numbers, and Python provides a variety of tools to help you
work efficiently with lists of numbers.
So once you understand how to use these tools effectively, your code will work well even when your
list contains millions of items.
So you can also use the range function.
So Python's range function makes it easy to generate a series numbers.
For example, you can use the range function to print a series of numbers like this.
For my value, my value here in range, for example, from 1 to 10.
And here we will print the print my value.
And here you will see us here.
And here you will see range from one, two, three, four, five, six, seven, eight, nine here.
So although this code looks like it should print the numbers from 1 to 10, it doesn't print the number
ten in this example range prints only the numbers from one through ten.
So I want to explain this by drawing something on the screen here like that, for example, this is
Range.
Here, for example, we wanted variables.
One, two, three, four, five, six, seven, eight, nine, nine.
Oops.
Nine and ten.
Here we when we ask range for a number from 1 to 10, it will give us from here.
And.
From 1 to 9.
So this is the number.
This code will give us here.
So.
As I said in this code, the range prints only numbers from one truth for truth nine.
It's let's run it again.
And here.
So this is the another result of the off by one behavior you will see often in programming languages
and the range function causes Python to start counting at the first value you give it and it stops when
it reaches the second value you provide because it stops at the second value.
The output never contains the end value, which would have been ten in this case to print numbers one
from 1 to 10, you will do this.
Just 11, right?
11 And that's it.
Here.
As you can see, we printed values from 1 to 10.
So if your output is different from what you expect when you are using range, try adjusting your end
value by one.
So you can also pass range only one argument and it will start a sequence of numbers at zero, for example
range.
Range.
Six here.
Will return the numbers from 0 to 6.
So you can also use the range to make a list of numbers.
So if you want to make a list of numbers, you can convert the results of range directly into list using
the list function.
So when you wrap list around the call to range function, the output will be a list of numbers in the
example the previous section.
In the example of previous section, we simply printed out series of numbers and we can use list to
convert that same set of numbers into a list.
So in order to do that, we will do numbers or my special numbers.
My special.
Actual numbers.
Numbers equals list here and range one.
One 6 or 111 here.
So now.
We have to add here and we will add after that, we will print the my special numbers.
That's it.
Here you can see the one, two, three, four, five, six, seven, eight, nine, ten.
So we can also use the range function to tell Python the skip numbers in a given range.
If you pass a third argument to a range here, Python uses that value as a step size when generating
numbers.
For example, here is our list.
The even numbers between 1 and 10 we will do here too, and we will do two here again and here.
And as you can see here, two, four, six, eight and ten.
So in this example, the range function starts with the value two and then adds two to that value.
It adds repeatedly until it reaches or passes the end value.
11 I want to also illustrate this on screen here.
So here we have one, two, three, four, five.
Five, six, seven, eight.
Nine.
Seven.
Eight, nine, ten.
Here.
So here.
What you see is.
So here we will we are seeing that we will start from two and end four from 1011.
But this means ten here, as you as we explained here.
So we will start from the two here.
So we will start first from this.
Two four, because as you can see here, we are passing two in each number.
And then we here we come here and here we go to.
Six.
And here we come, here and here we go to eight, and here we are.
And then we are going to ten.
And this is where our.
Range ends.
So you can create almost any sets of numbers or you want to use the.
So you can also create you can create almost any set of numbers you want to using the range function.
So for example, consider how might make a list of the first ten square numbers.
That is the square of each integers from one through ten in Python, which is two asterisks like that.
So let's actually close this.
So now here's how you might plot the first ten square numbers onto a list.
So here we have my special or my squares here, squares, and here we will create an empty list.
Now we will use the for loop my my value here in range.
And here we will start from 1 to 11.
And here we will use the my squares here equals my value asterisk to add an asterisk here.
And two and here we will use my my ears here that append.
Append.
Yeah.
My value here.
You must.
Here my squares that append.
My square here and it will change with my square equals my value.
62 And here we will use my squares that append the my.
Square.
And that's it.
And after that, of course, we will need to print the squares here.
Here, but outside the for loop.
As you can see here, we are printing outside for loop workers or my spare.
Yeah, that's it.
Now let's run it.
And as you can see here, one, four, nine, 16, 25, 38, 49, 64, 81 and 100.
So we start with an empty list called squares.
Actually, let me here.
So here we start with the empty list called my squares.
Here, let's actually use that marker.
So here we start with the empty list called my squares.
Then we tell Python to loop through each value.
Loop through each value.
From one.
210.
In this case, we read write 11 using the range function.
So inside the loop, the current value is raised to the second power and assigned to the variable.
My square.
Here.
Each new value of square is then appended to my square list here.
As you can see here we are using append here.
So this worked like that.
For example, this is our my squares here and here we added and then another loop comes.
We added another value and then another look loop comes.
We added another value inside it and until the ten times here.
So that's it.
And finally, when the loop has finished running, the list of squares is printed on the screen.