Bird
0
0

Which of the following is the correct syntax for an if statement in Python?

easy📝 Syntax Q12 of 15
Python - Conditional Statements
Which of the following is the correct syntax for an if statement in Python?
Aif x > 5 then:
Bif x > 5:
Cif (x > 5) {}
Dif x > 5 then
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python if syntax

    Python uses a colon : after the condition and no parentheses or 'then'.
  2. Step 2: Check each option

    if x > 5: uses if x > 5: which is correct. Others use 'then' or braces which are not Python syntax.
  3. Final Answer:

    if x > 5: -> Option B
  4. Quick Check:

    Python if ends with colon [OK]
Quick Trick: Python if ends with colon, no 'then' or braces [OK]
Common Mistakes:
MISTAKES
  • Adding 'then' after condition
  • Using braces {} like other languages
  • Forgetting the colon at the end

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes