Mike Driscoll Profile picture
$PYTHAI | Lead Developer @ThePSF #Python

Jul 24, 2022, 5 tweets

You need to know the basics of #Python to be able to use it effectively.

So let's talk about how you can slice a list. List slicing is where you use square brackets to "slice" out a subset of the list.

A slice is a portion of a list returned as a new list

🧵👇

Here is an example of slicing a #Python list:

You can also use negative values when slicing a #Python list

This example demonstrates using a negative value for the beginning of the slice while ALSO not specifying the end of the slice

You don't need to specify the beginning of a #Python list slice either.

In this example, I want to grab all the values starting at index 0 up to but not including index 3.

What do you think happens when you don't specify a beginning or an ending in a #Python list slice?

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling