Question:

What is the correct syntax for an if statement in Python?

Show Hint

Python uses a colon (:) after conditions and indentation for code blocks instead of curly braces {}. Always remember the structure: \texttt{if condition:}
Updated On: Mar 14, 2026
  • if(x > 10) {}
  • if x > 10 :
  • if x > 10 then :
  • if (x > 10) ::
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understand the structure of an if statement in Python.
In Python, the if statement is used to make decisions based on conditions. The syntax of an if statement requires a condition followed by a colon \(:\). After the colon, an indented block of code is written which executes if the condition is true.
The general syntax is \[ \texttt{if condition:} \] \[ \texttt{\ \ \ \ statement} \] Thus Python uses a colon and indentation rather than braces or keywords like "then".
Step 2: Analyze each option carefully.
Option (1): if(x > 10) {}
This syntax is similar to programming languages such as C, C++, or Java where curly braces are used. Python does not use braces for block statements, so this option is incorrect.
Option (2): if x > 10 :
This follows Python's correct syntax: a condition followed by a colon. The block of code would then be written on the next line with indentation. Therefore this option is correct.
Option (3): if x > 10 then :
Python does not use the keyword "then" in conditional statements. Hence this syntax is incorrect.
Option (4): if (x > 10) ::
Although parentheses can sometimes be used around conditions, Python does not use double colons. Hence this is also incorrect.
Step 3: Conclusion.
The only option that follows the proper Python syntax rules is \[ \texttt{if x > 10 :} \] Therefore the correct answer is option (2).
Was this answer helpful?
0
0