the strange arguments of range

前端 未结 4 1286
情深已故
情深已故 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:04

    As you know by now the real answer is that range is a C function which for some reason does not have the same rules of python (would be nice to know why).

    People might hate me for suggesting this but I've being doing this for range since I have a terrible memory of what the order of things are. Imo this shouldn't be a problem so I'm fixing it:

    range(*{'start':0,'stop':10,'step':2}.values())
    

    the reason I made it a one liner is because I don't want to have to define a range function that needs to be defined everywhere or imported everywhere. This is pure python.

提交回复
热议问题