I talked with my data science tutor for almost 20 minutes and he couldn't give me an answer beyond: "It just doesn't give you the last value. It's just something you remember."
With a negative "step", python keeps on yielding1 elements while the current value is greater than end. In this case, you start at 0. 0 is not greater than or equal to 10 so python's done and nothing gets yielded.
1This is a simplification of course -- range returns a range object on python3.x which is an indexable sequence type so it doesn't exactly yield, but the basic idea is the same ...
There is no evaluation of the first element by the range() call, and Python's range() function will not return anything if step is negative and start + i * step is not greater than stop. For your example, start = 0 + 0 * -1 is not greater than stop = 10, so your range call returns the empty list, and your for loop has nothing to iterate over.
$ python -c 'print(range(0,10,-1))'
[]
range()'s documentation:
range(stop)
range(start, stop[, step])
This is a versatile function to create lists containing arithmetic progressions. It is most often used in for loops. The arguments must be plain integers. If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0. The full form returns a list of plain integers [start, start + step, start + 2 * step, ...]. If step is positive, the last element is the largest start + i * step less than stop; if step is negative, the last element is the smallest start + i * step greater than stop. step must not be zero (or else ValueError is raised). Example:
Videos
For example, I want to print 1 from this range of numbers:
for n in range(1,101):
How to print (for ... in range () )( or using other methods )on the same line instead of spacing or skipping to the next lines below?