20.4 - Slicing a List
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Practice Questions
Test your understanding with targeted questions
What is the output of fruits[0:2] for the list fruits = ['apple', 'banana', 'mango', 'orange']?
💡 Hint: Look closely at the starting and ending indices.
If fruits = ['apple', 'banana', 'mango', 'orange'], what does fruits[:2] return?
💡 Hint: Remember ':' means from the beginning up to the index specified.
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What will fruits[0:3] return for the list fruits = ['apple', 'banana', 'mango', 'orange']?
💡 Hint: Think about the inclusive start and exclusive end of the range.
If fruits[1:] is executed, what will it return?
💡 Hint: What does omitting the end index signify?
2 more questions available
Challenge Problems
Push your limits with advanced challenges
You have a list of cities: cities = ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix']. Write a code snippet that uses slicing to return ['Chicago', 'Houston', 'Phoenix'].
💡 Hint: Think about how to access the elements starting from the index of 'Chicago'.
Given colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'], create a new list with just the warm colors: ['red', 'orange', 'yellow']. How would you slice for this?
💡 Hint: Identify the starting point and how many colors fall under 'warm'.
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.