What is correct syntax of Python if statement?



In Python, if keyword is used to execute on or more statements conditionally. The keyword is followed by a logical expression and : symbol. A block of increased indent containing one or more statements (stmt1 and stmt2 in following illustration)  is executed if the expression evaluates to true. If it is not true, statements if any (stmt3 below) after the indented block get executed.

if expr == True:
    stmt1
    stmt2
stmt3

Advertisements