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


On this page of the site you can watch the video online List slicing in Python with a duration of hours minute second in good quality, which was uploaded by the user Python Morsels 08 March 2024, share the link with friends and acquaintances, this video has already been watched 656 times on youtube and it was liked by 38 viewers. Enjoy your viewing!