Len() vs range()?


I am not understanding the functional difference between using len() and range(). For instance, in the code below I originally had for i in len(user_name) where for i in range(0, len(user_name) is.
Why is len() contained within range(), rather than simply using len()?

Thanks in advance!

The built in function range() will perform an action a specific number of times. Its parameters are start, stop, step.

the len() function returns the number of items in the length of an object.


In that particular code example, you’re starting at index 0 and going the length of the user_name. (The range of integers stops at -1.)

more on range():


Thank you for your response and the links!

1 Like