Python if Keyword
Definition and Usage
The if keyword is used to create conditional statements (if statements) and allows you to execute the code block only when the condition is True.
Use the else keyword to execute code when the condition is False, please refer to the following example.
More Examples
Example
Print "YES" if x is greater than 9, otherwise print "NO":
x = 5 if x > 9: print("YES") else: print("NO")
Related Pages
Please use our Python Condition Learn more about conditional statements in the tutorials.