How to use the range() function in Python

1 Basic grammar

The basic syntax of the range() function is shown below.

range(start, stop)

start means the first number in this series of numbers; stop-1 means the last number in this series of numbers. Note that stop is not included in the generated numbers. close before open

list(range(5))
[0, 1, 2, 3, 4]

Its stepping can be specified by the following syntax. Different from matlab, the step is parameter 3.

range(start, stop, step)
list(range(0,10,2))
[0, 2, 4, 6, 8]

Guess you like

Origin blog.csdn.net/weixin_44855366/article/details/129396457