if

KeywordPython 2.0+Beginner

Starts a conditional statement; executes block only if condition is true

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
temperature = 35

if temperature > 30:
    print("It's hot!")

x = 10
if x > 0:
    print("Positive")
elif x == 0:
    print("Zero")
else:
    print("Negative")

if evaluates a condition. The indented block runs only when the condition is True.

Try in Playground

Tags

languagesyntaxcorecontrol-flowconditional

Related Items