List range in python

Share:




List Range In Python 

What is  List range in python:

The range() function is used to generate a sequence of numbers over time. At its simplest, it accepts an integer and returns a range object (a type of iterable). 

For Example:

If We Want To Print numbers from 0 to 9 
You What to simply write the Print then parentheses open list again parentheses open range then number to which you want to print and close the both parentheses.
Here is the code:

print(list(range(10))

if you want to print numbers to 10 but you what to start from the 5 then you can
write list range first number to end number.

print(list(range(1,11)))

If you What to print Even Numbers then you write list range first number , end numbers, number of
which you have to give them gape for example I want 1 number gap so I write 2 because I want to
print even numbers.

print(list(range(0,11 ,2)))

Output:


[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

[0, 2, 4, 6, 8, 10]