Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Slices Introduction To Slices

What happens to the unnamed sliced list?

favorite_things[1:5] 
['whiskers on kittens', 'bright copper kettles', 'warm woolen mittens', 
'bright paper packages tied up with string']

In Kenneth's intro video to slices he gives a few examples of how lists are created from the slices that you execute....but how do you retrieve said unnamed lists? I'm assuming they're still stored in memory...but how're they accessed without a name to the list?

2 Answers

Mikhail Boldyrev
Mikhail Boldyrev
1,152 Points

I'm not an expert, but I don't think they are stored in memory if you don't assign a variable to them. You basically modify a copy of them temporarily so that you can use it somewhere else, but you don't have it tied in with a Variable so you can't actually use it somewhere else later.

If you wanted to rely on them and access them later, you'd have to tie them with a variable.

If you haven't assigned a name to the slice (or any other object), then you can not retrieve them later. Things are removed from memory by automatic garbage cleaner functions in higher level languages like this.