python-range () function

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/wsx_9999/article/details/102763640

range () function

range(start,end,step)

  • start: start counting from the beginning. The default is zero.
    For example: range (5) is equivalent to the range (0,5)
  • stop: stop counting to the end, but not stop.
    For example list (range (9,5)) is [0,1,2,3,4], no 5.
  • end: step size, default is 1.
    For example: range (0,5) is equivalent to the range (0,5,1)
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(1,10))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(1,10,4))
[1, 5, 9]
>>> list(range(10,-1,-1))
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

Guess you like

Origin blog.csdn.net/wsx_9999/article/details/102763640