Bird
0
0

Which of the following is the correct syntax for a for loop in Python?

easy📝 Syntax Q12 of 15
Python - For Loop
Which of the following is the correct syntax for a for loop in Python?
Afor (i=0; i<5; i++) print(i)
Bfor i to range(5) print(i)
Cfor i in range(5): print(i)
Dforeach i in range(5): print(i)
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python for loop syntax

    Python uses 'for variable in sequence:' followed by indented code. 'for i in range(5): print(i)' matches; others use wrong keywords or styles.
  2. Final Answer:

    for i in range(5): print(i) -> Option C
  3. Quick Check:

    Python for loop = for variable in sequence: [OK]
Quick Trick: Use 'for variable in sequence:' syntax in Python [OK]
Common Mistakes:
MISTAKES
  • Using 'to' instead of 'in'
  • Using C-style for loop syntax
  • Using 'foreach' which is not Python

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes