ITPub博客

首页 > IT职业 > IT图书 > range()——python2与python3不同之处

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

IT图书 作者:softwind 时间:2021-09-09 09:27:00 0 删除 编辑

当你在不同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).

    """

  

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4594/viewspace-2803159/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    111
  • 访问量
    842