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_suiteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| condition | expression | First truth test. |
| suite | statement suite | Selected when condition is truthy. |
| other_condition | expression | Optional subsequent test. |
| fallback_suite | statement suite | Optional fallback. |
Working Example
Example Snippetpython
score=75if score>=90: label='high'elif score>=60: label='pass'else: label='retry'print(label)