Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • 7
    Why wold you want to get a subarray starting at the length of the array (a[len(a):])? Shouldn't this just return an empty subarray always since there are no elements after index len(a) - 1? Commented Jun 13, 2020 at 1:10
  • 2
    @AjaxLeung empty slices are useful because you can assign to them: a = list(range(0,10)) print('a\t', a) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print('slice\t', a[3:3]) # [] a[3:3] = [10,10,10] print('new a\t', a) # [0, 1, 2, 10, 10, 10, 3, 4, 5, 6, 7, 8, 9] Commented Jan 30, 2021 at 2:46

lang-py