Videos
I first thought that it just returns numbers and you can do a lot of stuff with those numbers but now I am seeing that it is being used to run a loop a specific number of times. It's just not making sense to me why this works, like I can't intuitively understand it.
Tho I have started using in my code, an explanation on why it was developed this way would help.
I've been using range() in for loops and thought range() simply returns a list, tuple or set containing a sequence of numbers. But when I tried print(x) where x = range(5), It simply gave out range(0, 5). I thought the output would be something like: [0, 1, 2, 3, 4].
My reason for thinking like that is because if I were to put a variable x (where x = range(5)) in a for loop, the for loop behaves exactly as if x = [0, 1, 2, 3, 4]. So, why does the range() behave differently if I use it outside a for loop.
I hope my question makes sense. Thank you in advance.
Edit: Thank you everyone. Your answers cleared up my confusion.