the strange arguments of range

前端 未结 4 1288
情深已故
情深已故 2020-12-10 12:32

The range function in python3 takes three arguments. Two of them are optional. So the argument list looks like:

[start], stop, [step]

This means (correct me

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 13:12

    range does not take keyword arguments:

    range(start=0,stop=10)
    TypeError: range() takes no keyword arguments
    

    it takes 1, 2 or 3 positional arguments, they are evaluated according to their number:

    range(stop)              # 1 argument
    range(start, stop)       # 2 arguments
    range(start, stop, step) # 3 arguments
    

    i.e. it is not possible to create a range with defined stop and step and default start.

提交回复
热议问题