0
0
Pythonprogramming~15 mins

List indexing and slicing in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
List Indexing and Slicing
๐Ÿ“– Scenario: You are organizing a small collection of your favorite fruits. You want to practice how to pick specific fruits from the list using their positions.
๐ŸŽฏ Goal: Learn how to use list indexing and slicing to select individual items and groups of items from a list.
๐Ÿ“‹ What You'll Learn
Create a list with exact fruit names
Create variables to hold specific index positions
Use list indexing to get a single fruit
Use list slicing to get a group of fruits
Print the selected fruits
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Selecting items from a list is like picking fruits from a basket by their position. This helps when you want to work with parts of a collection.
๐Ÿ’ผ Career
Understanding list indexing and slicing is essential for data handling, filtering, and processing in many programming jobs.
Progress0 / 4 steps
1
Create the fruit list
Create a list called fruits with these exact items in order: 'apple', 'banana', 'cherry', 'date', 'elderberry'.
Python
Need a hint?

Remember to use square brackets [] to create a list and separate items with commas.

2
Set index variables
Create two variables: first_index set to 0 and slice_start set to 1.
Python
Need a hint?

Just assign the numbers 0 and 1 to the variables as shown.

3
Use indexing and slicing
Create a variable first_fruit that gets the fruit at first_index from fruits. Then create a variable some_fruits that slices fruits from slice_start up to (but not including) 4.
Python
Need a hint?

Use square brackets with the index variable for single item, and with start:end for slicing.

4
Print the selected fruits
Print first_fruit and some_fruits each on its own line.
Python
Need a hint?

Use two print statements, one for each variable.