From the course: Hands-On Introduction: Python
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Getting what you need from lists with slices - Python Tutorial
From the course: Hands-On Introduction: Python
Getting what you need from lists with slices
- [Presenter] There's a plethora of data types there that represent collections in Python, but by far, the most common one you'll encounter is the list. It's mutable, it's flexible it offers a ton of functionality. And let's have a look at what we can do with lists. So here we have a collection of names, John, Paul, George, and Ringo, the Beatles. And we have some arbitrary ages, 20, 21, 22, and 23. The first thing you'll notice is that, you can sort of access these like you would in array in other languages. So the zero place, which is the first item in this names collection, is John. So we can grab that with just a zero in brackets. Paul being the second one is in the first place, because it's zero indexed. Then we have John and Paul, and here we're using something called the slice. It's a very powerful feature of Python's lists, and it also works with strings and other data types. So for example, names to the…