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.

LS

Related Python Mentoring answers

All answers ▸

Create a program that checks for syntactical errors in an email address.


Write a program that takes a value x and then outputs x Fibonnaci numbers. E.g. if x=6 output would be 1 1 2 3 5 8


Which four data types are used in Python? Can you give an example of each?


Sort a given input of lowercase letters alphabetically