Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Python
Stage 5: Specialization

Part 01 / Topic 7 of 7

print(), comments and indentation

print() shows output. You can pass many values, and change the separator (sep) and line ending (end). Comments start with #. Python ignores them. Use them to explain why. Indentation (spaces at the start of a line) is part of Python's grammar. Use 4 spaces. Code inside a block (like if, which you will learn in Part 3) must be indented.

Real-world example: Print a small welcome banner for a shop.

# Print many values in one call
print("Python", "is", "fun")          # Python is fun
print("26", "11", "2026", sep="/")     # 26/11/2026
print("Loading", end="...")
print("done")                          # Loading...done

"""A triple-quoted string can span many lines.
Here, in the middle of the code, it is just a string used like a comment.
Only at the very top of a file or function is it called a docstring."""

# `if` runs the indented line only when the condition is True (Part 3)
shop_open = True
if shop_open:
    print("Welcome to Sharma General Store")   # 4 spaces before print
# Welcome to Sharma General Store
Escape Meaning Example Output
\n New line print("A\nB") A, then B on next line
\t Tab print("A\tB") A, a tab space, then B
\\ Backslash print("C:\\temp") C:\temp
\" Quote print("He said \"Hi\"") He said "Hi"

๐Ÿ” Going deeper: The full signature is print(*values, sep=" ", end="\n", file=None, flush=False) โ€” file=None means "write to the screen" (sys.stdout). print() turns each value into text with str() first. Use flush=True when you need output to appear at once (for example, progress messages in a slow script).

๐Ÿงช Quick quiz โ€” answer from memory, then check.

  1. What does print("a", "b", sep="-") show?
  2. What starts a comment?
  3. How many spaces does this course use for one level of indentation?
Show the answers
  1. a-b
  2. # โ€” Python ignores the rest of the line.
  3. 4 spaces.

Done here? The practice set for Part 1 โ€” 6 exercises with solutions โ€” is on the part page.

Search the guide