What is the difference between using range() and a list of values?

The main differences between the two boil down to the difference between greedy and lazy evaluation. With a list, each indexed object takes up some space in memory. Range, however, calculates the next value on the fly, meaning only one object is stored in memory each time. However, this means range has to calculate each successive value, slowing down the processing speed.

Answered by Luke S. Python tutor

876 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

How do I use format python code?


Write a python function that takes a string as parameter and returns the character in the string with the most occurrences, along with the number of times this character occurs


Write a function with arguments r, dr that will return a 2D array of size (r/dr, r/dr). In the array "draw" two circles and assign them a value of 1. Separate the two circles by adding a nan circle of equal width.


Sort a given input of lowercase letters alphabetically


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy