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.
What will be the output of the following code? fruits = ['apple', 'banana', 'mango']; for fruit in fruits: print(fruit)
Think about what each element in the list is.
How do you access the first element of the list using indexing?
Remember, indexing starts from 0!
What is the output of the code fruits = ['apple', 'banana', 'mango']; for i in range(len(fruits)): print(fruits[i])?
Think of what the loop is doing with each index.
True or False: Using for fruit in fruits is the only way to traverse a list.
Consider the different methods we've discussed.
Write a function that takes a list of numbers and returns a new list with each number doubled using traversal.
Consider how the items should be processed as you traverse the list.
Given a 2D list, write a function that returns the sum of all the inner lists by traversing.
You will need to traverse the outer list and then the inner lists.
4 more questions in this section. Enroll free to practise them all.
Enroll free