Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
For fruits = ["apple", "mango", "kiwi", "plum"], find fruits[0], fruits[-1], fruits[1:3] and len(fruits).
Positions start at 0, and a slice stops before its end.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
fruits[0] is the first item: apple.fruits[-1] is the last item: plum.fruits[1:3] has the items at positions 1 and 2: ['mango', 'kiwi']. It stops before 3.len(fruits) is 4.Log in to join the discussion.
Loading…