Python BasicsCore· 30 min read

Syntax, print & Comments

The basic rules: printing output, comments, and Python’s famous indentation.

What you will learn

  • Print output with print()
  • Write comments
  • Understand indentation

print() shows output

The print() function is how your program talks back to you — it shows text and numbers on the screen. Whatever you put inside the brackets gets displayed.

print() outputs to the screen
print("Hello")
print("Learning", "Python")   # print can take several values
print(5 + 5)

Line 1 prints the word Hello. Line 2 passes two values separated by a comma — Python prints them on one line with a space between, giving Learning Python. Line 3 has no quotes, so Python first works out the sum 5 + 5 and then prints the result, 10. Text in quotes is shown exactly; a sum without quotes is calculated first.

Note: Output: Hello Learning Python 10

Comments

A comment starts with #. Python ignores it — use it to explain your code.

Comments start with #
# This is a comment
print("Visible")   # comments can go at the end of a line

The first line is only a comment, so Python skips it entirely — nothing prints from it. The second line runs the print() and shows Visible; the # comments can go… part after it is ignored. Comments are notes for humans reading the code, never instructions for the computer.

Note: Output: Visible

Indentation matters!

Unlike most languages, Python uses indentation (spaces at the start of a line) to group code — not curly braces. Code inside an if or loop must be indented (usually 4 spaces).

Indentation groups code
if 5 > 2:
    print("Five is bigger")   # indented = inside the if
print("Always runs")          # not indented = outside

The first line asks a question: is 5 greater than 2? Because it is true, the indented line below it runs and prints Five is bigger. The last line is not indented, so it sits outside the if and always runs — printing Always runs no matter what. The spaces at the start of a line are how Python knows which lines belong to the if.

Note: Output: Five is bigger Always runs

Watch out: Wrong indentation causes an IndentationError. Be consistent — use 4 spaces for each level. Do not mix tabs and spaces.

Q. How does Python know which code is inside an if statement?

Answer: Python uses indentation (typically 4 spaces) to group code blocks instead of braces.

✍️ Practice

  1. Print three lines about yourself.
  2. Write an if with a correctly indented line inside it.

🏠 Homework

  1. Add comments explaining each line of a small script.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →