List slicing in Python

Published: 08 March 2024
on channel: Python Morsels
656
38

In Python, slicing looks like indexing with colons (:). You can slice a list (or any sequence) to get the first few items, the last few items, or all items in reverse.

Read an article version of this video at https://pym.dev/slicing/

Find more Python screencasts at https://pym.dev/screencasts/

00:00 Getting the first N elements from a list
00:28 Slicing makes a new list
00:37 The start index is inclusive but the stop index is exclusive
01:27 Default slice start/stop values
01:50 Why the stop index isn't included in slices
02:38 Negative indexes work too
03:01 Out-of-bounds slicing is allowed
03:41 The slice step value
04:38 Slicing works on all sequences
05:03 The most common uses for slicing in Python
05:20 Use slicing to get "slices" of sequences in Python

#Python


Watch video List slicing in Python online without registration, duration hours minute second in high quality. This video was added by user Python Morsels 08 March 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 656 once and liked it 38 people.