π
Python Syntax
Indentation, comments, and basic rules
Reward
+30 XP
Indentation
Python uses indentation (whitespace at the beginning of a line) to define code blocks. Other languages use curly braces. The standard is 4 spaces.
if True:
print("Indented correctly")
# This would cause an error:
# if True:
# print("No indent")Comments
Use # for single-line comments. Python has no built-in multi-line comment syntax, but you can use triple-quoted strings.
# This is a comment
print("Hello") # Inline comment
"""
This is a
multi-line string used
as a comment
"""Try it yourself
Run the example below. Edit it and see what changes.
main.py
Output
Press Run to execute (Ctrl/Cmd+Enter)
Common mistakes
- β Mixing tabs and spaces β pick one and stick with it (spaces preferred).
- β Forgetting to indent after if, for, while, def, class, etc.
