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

Timeline for answer to Colon (:) in Python list index by soulseekah

Current License: CC BY-SA 4.0

Post Revisions

14 events
when toggle format what by license comment
Mar 3, 2021 at 12:07 comment added soulseekah @TomCharlesZhang these are operators operating on an iterable. If you just [1:5] Python doesn't understand what you're operating on. It has to be something like "Hello World"[1:5] for example, or ['a','b','c','d', 'e','f','g'][1:5]
Feb 9, 2021 at 3:34 comment added Methodox Charles Zhang Why am I getting invalid syntax when I write [1:5] in python interpreter?
Jun 13, 2020 at 1:12 comment added Ozymandias Your last example needs more explanation. "from length of a to end". Shouldn't this always return an empty array? There's nothing at "length of a". The last index of a should be len(a) - 1, right?
S May 25, 2020 at 9:49 history suggested BUFU CC BY-SA 4.0
the question already is about lists and it does *not* work with dictionaries
May 25, 2020 at 9:45 review Suggested edits
S May 25, 2020 at 9:49
Mar 12, 2018 at 19:42 history edited jfountain CC BY-SA 3.0
Updated link to go directly to the point where the issue in question is referenced.
Sep 7, 2017 at 16:09 comment added Dave Voyles Your explanation of ":" meaning "to end" is what really allowed me to understand. Thank you.
Apr 28, 2016 at 19:48 comment added Joe Also you can have step in there: [start:end:step], which is why [::-1] reverses with normal start and end, but backwards step.
Jul 4, 2015 at 2:31 comment added Steve Zelaznik Does not work with dictionaries. applying d[:5] is the eqivalent of d.__getitem__(slice(0, 5, None)). A slice is not hashable.
Dec 19, 2014 at 5:50 vote accept kuriouscoder
Aug 3, 2013 at 11:25 comment added Edub Kendo Because it's not actually that easy to Google punctuation like ':', I particularly appreciated finding your answer and found it helpful. Even using something like symbolhound, its so commonly used that I was afraid I wouldn't be able to find an answer quickly.
Oct 25, 2010 at 8:04 history edited soulseekah CC BY-SA 2.5
added 17 characters in body
Oct 25, 2010 at 7:51 comment added Garrett Hyde Remember that [1:5] starts with the object at index 1, and the object at index 5 is not included. You can also make a soft copy of a list with [:]
Oct 25, 2010 at 6:53 history answered soulseekah CC BY-SA 2.5