Does range() really create lists?

前端 未结 4 1535
情话喂你
情话喂你 2020-12-03 04:04

Both my professor and this guy claim that range creates a list of values.

\"Note: The range function simply returns a list containing th

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 05:07

    It depends.

    In python-2.x, range actually creates a list (which is also a sequence) whereas xrange creates an xrange object that can be used to iterate through the values.

    On the other hand, in python-3.x, range creates an iterable (or more specifically, a sequence)

提交回复
热议问题