The Python range() Function: Recap
You now understand how to use range()
and work around its limitations. You also have an idea of how this important function has evolved between Python 2 and Python 3. The next time you need to perform an action a specific number of times, you’ll be all set to loop your heart out!
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
In this course, we saw how we can use Python’s range()
function to generate lists of numbers to iterate over. We learned how to create lists of incrementing and decrementing numbers, how to reverse a list, and how to use this range()
function alongside the for
loop to perform some sort of operation on each value in our generated list.
00:26
We also saw some of the technical limitations behind generating floating-point values, and we learned how the range()
function has evolved from Python 2 to Python 3, notably how range()
has replaced xrange()
.
00:45
I hope you can see now why the range()
function is so powerful. Whatever you are working on, you’re bound to run into a scenario where you need to iterate over a chunk of code x number of times, and you might even need to use that incrementing variable within your code.
Richard Childers on Nov. 3, 2019
Good course. Clear, easy to understand, covered the basics well.
mikesult on March 1, 2020
Thank you Austin, this solidified my knowledge regarding range() and numpy.arange()
Ghani on Oct. 15, 2020
Thank you Austin for this very useful tutorial!
boricua21dale on Nov. 29, 2020
This course was awesome! def helped me go over the basics, its been a while since I’ve dove into Python. Thanks Austin!
Become a Member to join the conversation.
JulianV on Oct. 22, 2019
Great information.