Bird
0
0

Which of the following is the correct syntax to loop through all items in a list named fruits?

easy📝 Syntax Q12 of 15
Python - Magic Methods and Operator Overloading
Which of the following is the correct syntax to loop through all items in a list named fruits?
Afor fruit in fruits:
Bfor fruits in fruit:
Cloop fruit in fruits:
Dforeach fruit in fruits:
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct for-loop syntax in Python

    Python uses for variable in collection: to loop through items.
  2. Step 2: Match variable and collection names

    The variable should be singular (fruit) and collection plural (fruits) for clarity and correctness.
  3. Final Answer:

    for fruit in fruits: -> Option A
  4. Quick Check:

    for item in list: is correct syntax [OK]
Quick Trick: Use 'for item in collection:' to loop in Python. [OK]
Common Mistakes:
  • Swapping variable and collection names
  • Using 'foreach' which is not Python syntax
  • Writing 'loop' instead of 'for'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes