How explain Python range not include end? is there a range alternative?

for my bit unexpected 23 is the result of the following source.

I would have expected 234 or 3. either included or not included. but the begin is inclusive and end is exclusive.

compared in mathematics [2, 4] = 2, 3, 4 and [2, 4) = 2, 3 and (2, 4) = 3.

how can we best remember or explain this behavior? and is there a function makes the same all inclusive (more pretty then range(2, 4+1)?

for xLoop in range(2, 4):
    print (xLoop)

used is python 3.6.9

Read more here:

Content Attribution

This content was originally published by SL5net at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: