Language Syntax

If — Python syntax

Evaluate conditions in order and execute at most one matching suite. Conditions use truth testing, not a requirement to equal True. Both elif and else clauses are optional; multiple elif clauses are allowed.

Formal Syntax & Structure

python syntaxpython
if condition:    suiteelif other_condition:    other_suiteelse:    fallback_suite

Parameters & Attributes

NameTypeDescription
conditionexpressionFirst truth test.
suitestatement suiteSelected when condition is truthy.
other_conditionexpressionOptional subsequent test.
fallback_suitestatement suiteOptional fallback.

Working Example

Example Snippetpython
score=75if score>=90:    label='high'elif score>=60:    label='pass'else:    label='retry'print(label)
Python Reference