Search the courses, subjects, tracks, games and features, or jump straight to a page.
2 cards from this section. Quick, good the night before a test.
What is the output of fruits[0:2] for the list fruits = ['apple', 'banana', 'mango', 'orange']?
Look closely at the starting and ending indices.
If fruits = ['apple', 'banana', 'mango', 'orange'], what does fruits[:2] return?
Remember ':' means from the beginning up to the index specified.
What will fruits[0:3] return for the list fruits = ['apple', 'banana', 'mango', 'orange']?
Think about the inclusive start and exclusive end of the range.
If fruits[1:] is executed, what will it return?
What does omitting the end index signify?
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'].
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?
Identify the starting point and how many colors fall under 'warm'.
6 more questions in this section. Enroll free to practise them all.
Enroll free