Skillversitas

Basic Syntax

Python uses indentation (spaces) to mark code blocks, not curly braces like other languages. This makes Python code very clean and easy to read.

This indentation rule must be followed — if the indentation is inconsistent, Python will raise an IndentationError error. The community-agreed convention is to use 4 spaces for each indentation level. You can configure your editor to automatically convert tabs to spaces to avoid the mix of tabs and spaces that often causes bugs.

In addition to indentation, Python also has naming conventions recommended in PEP 8 — the Python code style guide. Variables and functions use snake_case (lowercase with underscores between words), classes use CamelCase, and constants use UPPER_CASE. Following these conventions makes your code easy to understand for other Python programmers.

Python Syntax Rules:

  • Python is case-sensitive (distinguishes uppercase/lowercase)
  • Each statement ends with a new line (no semicolon needed)
  • Standard indentation is 4 spaces
  • Single-line comments use the # symbol
  • Multi-line comments use three quotation marks """

Code Example

# This is a single-line comment

"""
This is a multi-line comment
that can span
several lines of text
"""

name = "Python"
version = 3.13

if version > 3:
    print(f"{name} version {version}")  # f-string
    print("Indentation is required!")

Code Explanation

The first line is a single-line comment — all text after # is ignored by the interpreter. The """...""" block is a multi-line comment, useful for documenting functions or classes (called a docstring). The name and version variables store a string and a float. The if version > 3: structure checks a condition; if it is true, the two lines below are executed. Notice that both lines have the same indentation (4 spaces), indicating they belong to the if block. The print function uses an f-string (prefixed with f before the string) to insert variable values directly into the text using curly braces {}.

Everyday Example

You are building a program to check exam grades. A student passes if the grade is >= 70:

"""
Student pass/fail checking program
"""
student_name = "John"
score = 85

if score >= 70:
    print(f"{student_name} is PASSED")
    print(f"Grade: {score}")
else:
    print(f"{student_name} is NOT PASSED")
    print(f"Grade: {score}")

In this case, the indentation determines which block runs depending on the result of the score >= 70 check.

Summary

Python syntax is designed for maximum readability. Indentation is not just style, it is part of the language structure. Master the indentation rules and naming conventions, and you will write Python code that is clean, tidy, and easy to maintain.