Recall & Review
beginner
What is list indexing in Python?
List indexing means accessing an element in a list by its position number. Positions start at 0 for the first item.
Click to reveal answer
beginner
How do you access the last item of a list using indexing?
Use index -1 to get the last item of a list. For example,
my_list[-1] gives the last element.Click to reveal answer
beginner
What does list slicing do?
List slicing extracts a part of the list by specifying a start and end position. It creates a new list with those elements.
Click to reveal answer
intermediate
Explain the syntax
my_list[start:end] in slicing.It means take elements from position
start up to but not including end. If start is omitted, it starts from the beginning. If end is omitted, it goes to the end.Click to reveal answer
intermediate
How can you get every second element from a list using slicing?
Use the step value in slicing:
my_list[::2] returns every second element starting from the first.Click to reveal answer
What is the index of the first element in a Python list?
✗ Incorrect
Python lists start indexing at 0, so the first element is at index 0.
What does
my_list[-2] return?✗ Incorrect
Negative indexes count from the end. -1 is last, so -2 is second last.
What will
my_list[2:5] return?✗ Incorrect
Slicing includes start index but excludes end index, so indexes 2, 3, 4.
How do you get a copy of the whole list using slicing?
✗ Incorrect
Using
my_list[:] returns a new list copy with all elements.What does
my_list[1:6:2] do?✗ Incorrect
The third number is the step, so it picks elements at indexes 1, 3, 5.
Describe how to access elements in a list using positive and negative indexes.
Think about counting from the start and from the end.
You got /3 concepts.
Explain how list slicing works and how to use start, end, and step values.
Imagine cutting a piece from a list with rules.
You got /4 concepts.