Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
Access the first element from the list fruits = ['apple', 'banana', 'mango'].
Remember to use index 0.
What does fruits[-1] return if fruits = ['apple', 'banana', 'mango']?
Think about the last item in the list.
What will fruits[0] return if fruits = ['apple', 'banana', 'mango']?
Look at the first position in the list.
Is fruits[-1] equal to the last item in the list?
Think about what -1 refers to.
Given the list mixed = [5, 'cat', 'dog', 9.0, True], find the value at index 2 and at index -1.
Use both positive and negative indices to retrieve the values.
You have a list of names: names = ['Alice', 'Bob', 'Charlie', 'David']. Write an expression to print the second and third names using negative indexing.
Think about how negative indexing works from the end.
6 more questions in this section. Enroll free to practise them all.
Enroll free