Advertisement

Python Syntax & Comments

Previous Lesson 220 of 233 Next
Advertisement
Lesson Overview: Understand indentation blocks and single/multi-line comments.

Indentation Is Meaningful

Python uses consistent leading spaces (conventionally 4 spaces) to group statements under if, for, def, and class blocks. Comments begin with #.

  • Consistent 4-space indentation avoids IndentationError
  • Use # for inline comments and triple quotes for docstrings

Indentation & Comment Example (Editable — type & Run)

Advertisement

Test Yourself With Exercises

Write a single-line Python comment before print():

Print greeting\nprint("Hi")
Advertisement