Definition
Why can a single space at the start of a line break a Python program?
print() displays values on the screen. A comment, starting with #, is a note for people that Python ignores. A statement is one instruction. Python uses indentation, spaces at the start of a line, to group statements into blocks, so indentation is part of the syntax.
In simple words
print("Name:", "Riya") shows Name: Riya, with a space added between the items. # lines are like pencil notes in the margin: the reader sees them, Python skips them. Indentation is like the steps of a recipe that belong to 'while the milk boils': they are pushed in to show they are inside.
Why it matters
Clear output and good comments make programs easy to check and share. Indentation errors are among the most common problems for beginners, so understanding them early saves a lot of frustration.
How it works
- print() can take several items separated by commas; sep changes the separator and end changes what comes at the end.
- Use four spaces for each level of indentation, and be consistent.
- A line ending with a colon, such as if or for, must be followed by an indented block.
In code
Comments explain the program; sep and end shape the output.
# A profile card, printed neatly
name = "Riya"
city = "Pune"
hobbies = 3
print("=" * 20)
print("Name:", name)
print("City:", city)
print("Hobbies", hobbies, sep=": ")
print("Loves AI", end="!")
print() # an empty print moves to a new line
print("=" * 20)Output
==================== Name: Riya City: Pune Hobbies: 3 Loves AI! ====================
Try it yourself
Will it run?
Decide whether each small program runs or gives an error.
print("Hello") # say hi
print("Missing quote)
print("A", "B", sep="-")
print("Hello") (spaces before print, nothing above)
Common mistakes
- Mixing tabs and spaces for indentation.
- Indenting a line that isn't inside a block.
- Writing comments that repeat the code instead of explaining why.
Check yourself
Summary
- print() shows output; sep and end control spacing.
- Comments start with # and are ignored by Python.
- Indentation defines blocks: use four spaces, consistently.
Finished reading?
Sources: PEP 8: Style Guide for Python Code