If Statements
If statements let your code make decisions based on conditions.
Basic If Statement
Loading Python Playground...
Note: Python uses indentation (4 spaces) to define code blocks, not curly braces.
Exercises
Loading Python Exercise...
Loading Python Exercise...
If with Multiple Statements
Loading Python Playground...
Nested If Statements
Loading Python Playground...
Loading Python Exercise...
Multiple Conditions
Loading Python Playground...
Loading Python Exercise...
Checking Truthiness
Loading Python Playground...
Loading Python Exercise...
Practice Playground
Loading Python Playground...
Key Takeaways
if condition:followed by indented code block- Python uses 4 spaces for indentation
- Combine conditions with
and,or,not - Empty values (
'',[],None,0) are falsy - Use
is Noneto check for None

