Python List Slicing with None as argument

后端 未结 4 599
旧时难觅i
旧时难觅i 2020-12-16 11:56

Via trial and error I found out that

my_list = range(10)
my_list[:None] == my_list[:]

I use this for django query sets so I can define a si

4条回答
  •  被撕碎了的回忆
    2020-12-16 12:50

    It should be safe. In Python, something[] is equivalent to something[slice(...)], and the documentation for the slice type clearly indicates that the arguments for stop and step default to None.

提交回复
热议问题