Edit: I think I need another coffee, I guess you meant that using range(1, 100, step) could only ever reach a maximum of 99. In that case the text is a little hazy. If you treat the stopping point as the value passed to range then it makes sense but it could easily be read as the maximum possible value (regardless of step). A bit ambiguous I’d agree.
Original-
Since range takes arguments along the lines of (start, stop, step) I’d say it’s an accurate statement that the number 101 would not appear because it is greater than the stop value.
I think the confusion may come from the use of ‘sequence’ which is guess refers to the sequence of numbers which insreases by 10 each time (xn = 10n + 1) and not to the range object itself which has strict limits.
Looking at the explanation of the page, which says:
By default, range creates a list starting at 0 . However, if we call range with two arguments, we can create a list that starts at a different number. For example, range(2, 9) would generate numbers starting at 2 and ending at 8 (just before 9 )
The page defines the “ending number” one before the written number for function argument. In that way, the stopping point is where the function stops the range, regardless of step number. In other words, we can create a range from 2 (starting point) to 8 (stopping point) by giving 2 and 8+1 as parameters to the function range(x,y) that is starting at x=2 and stopping at y-1=8.
Or maybe my interpretation is not correct.
It’s just because the range function is only designed to work with integers. There are good reasons for this as you’d want to be avoiding floats wherever possible. A simple solution is to do something like multiply/divide your range output by a float e.g. [x * 0.1 for x in range(10)] but you will wind up with floating point errors this way. You could mix this with something like the Decmial or Fractions module to try to minimise long term rounding errors if you continue to use these values but where possible it’s better just to try and avoid them.
If you’re doing this a lot you could use the thrid party but nontheless exceedingly popular numpy library which has options for creating floating ranges (linspace or arange) but they’re actual arrays and not as memory efficient as range itself.
I wonder, is it actually possible to create a range in reverse order (like starting from 10 and then 9, 8, 7 … etc), or are the range values always sorted from smallest to largest?
If you consult python documentation you can see that range accepts up to 3 arguments: start, stop en step. Where you can make the steps negative (-1 for example). Then the values will decrease
How is the second parameter of the range() function required (and presumably not preset), but the first value has a preset?
If I create a function (e.g. def simple_function(a = "value 1", b, c = "value 2"):) where a parameter without a preset value follows a parameter with a preset value, then I get an error message: