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 the position of kiwi, and test if fig is in the list.
index gives the position. in gives True or False.
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.index("kiwi") is 2, the position of kiwi."fig" in fruits is False.Note. index stops with a ValueError if the value is not in the list. So check with in first, or catch the error.
Log in to join the discussion.
Loading…