0

What does the third argument in range do ? I'm confused

Third argument in range

14th Jan 2022, 3:25 AM
Ashutosh Singh
Ashutosh Singh - avatar
5 Respostas
+ 5
You can simply think it like: start, stop, step = 0, 11, 2 index = start while index != stop: print(index) index += step >>> help(range) Help on class range in module builtins: class range(object) | range(stop) -> range object | range(start, stop[, step]) -> range object | | Return an object that produces a sequence of integers from start (inclusive) | to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1. | start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3. | These are exactly the valid indices for a list of 4 elements. | When step is given, it specifies the increment (or decrement). https://www.python.org/dev/peps/pep-0204/
14th Jan 2022, 3:56 AM
FanYu
FanYu - avatar
+ 1
integer value which determines the increment between each integer in the sequence // https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-range-function/amp/
14th Jan 2022, 3:40 AM
NEZ
NEZ - avatar
0
So it determines the gap between the two numbers ?
14th Jan 2022, 3:47 AM
Ashutosh Singh
Ashutosh Singh - avatar
0
Ashutosh Singh, yes See my comment and open that link.
14th Jan 2022, 3:49 AM
NEZ
NEZ - avatar
0
Ok thanks ! ^_^
14th Jan 2022, 3:51 AM
Ashutosh Singh
Ashutosh Singh - avatar