About 6,540,000 results
Open links in new tab
  1. slice - How slicing in Python works - Stack Overflow

    The colon, :, is what tells Python you're giving it a slice and not a regular index. That's why the idiomatic way of making a shallow copy of lists in Python 2 is

  2. How can I use Python built-in slice object? - Stack Overflow

    Oct 12, 2010 · The index or slice is passed to the methods as a single argument, and the way Python does this is by converting the slice notation, (1:10:2, in this case) to a slice object: …

  3. What does the slice() function do in Python? - Stack Overflow

    Jul 19, 2015 · Whenever some other code uses slice notation on your an instance of your class Python will call your __getitem__ method with a slice object. (Older versions of Python used a …

  4. How to slice a list from an element n to the end in Python?

    To my understanding, slice means lst[start:end], and including start, excluding end. So how would I go about finding the "rest" of a list starting from an element n?

  5. What is :: (double colon) in Python when subscripting sequences?

    Aug 10, 2010 · 22 When slicing in Python the third parameter is the step. As others mentioned, see Extended Slices for a nice overview. With this knowledge, [::3] just means that you have …

  6. How to get last items of a list in Python? - Stack Overflow

    Nov 23, 2019 · 108 Slicing Python slicing is an incredibly fast operation, and it's a handy way to quickly access parts of your data. Slice notation to get the last nine elements from a list (or any …

  7. Slicing a list using a variable, in Python - Stack Overflow

    May 13, 2012 · Given a list a = range(10) You can slice it using statements such as a[1] a[2:4] However, I want to do this based on a variable set elsewhere in the code. I can easily do this …

  8. Python: slicing a multi-dimensional array - Stack Overflow

    Feb 27, 2023 · Python's slicing also doesn't support 2D/multi-dimensional slicing for lists. The expected output for slicing a multi-dimensional list can be tricky. For example, If you want the …

  9. Python slice first and last element in list - Stack Overflow

    Aug 31, 2012 · 45 Python 3 only answer (that doesn't use slicing or throw away the rest of the list, but might be good enough anyway) is use unpacking generalizations to get first and last …

  10. python - How to take column-slices of dataframe in pandas

    May 19, 2012 · 27 You can slice along the columns of a DataFrame by referring to the names of each column in a list, like so: