互联网技术 / 互联网资讯 · 2024年1月24日

Python内置函数-range() 的云计算开发指南

描述 Python2.x Range() 函数可创建一个整数列表,一般用在 foR 循环中。 注意:Python3 Range() 返回的是一个可迭代对象(类型是对象),而不是列表类型, 所以打印的时候不会打印列表。 语法 以下是 Range() 方法的语法: Range(staRt, stop[, step]) 参数 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) 返回值 返回对象长度。 实例 以下实例展示了 len() 的使用方法: 以下是 Range 在 foR 中的使用,循环出Runoob 的每个字母:

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册