函数语法
range(start, stop[, step])每组词 www.cgewang.com
参数说明:
- start: 计数从 start 开始。默认是从 0 开始。例如range(5)等价于range(0, 5);
- stop: 计数到 stop 结束,但不包括 stop。例如:range(0, 5) 是[0, 1, 2, 3, 4]没有5
- step:步长,默认为1。例如:range(0, 5) 等价于 range(0, 5, 1)
实例
以下是 range 在 for 中的使用,循环出runoob 的每个字母:
>>>x = ‘runoob‘ >>> for i in range(len(x)) : ... print(x[i]) ... r u n o o b >>>
Python range() 函数用法
原文:https://www.cnblogs.com/yc10086/p/13379951.html