栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

range()——python2与python3不同之处

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

range()——python2与python3不同之处

当你在不同python版本下使用 range() 时, 需要注意了

PY2

def range(start=None, stop=None, step=None): # known special case of range

    """

    range(stop) -> list of integers

    range(start, stop[, step]) -> list of integers

     

    Return a list containing an arithmetic progression of integers.

    range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.

    When step is given, it specifies the increment (or decrement).

    For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!

    These are exactly the valid indices for a list of 4 elements.

    """

    pass

PY3

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).

    """

  

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/224466.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号