Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

Python Syntax Basics: How Brackets, Colons, and Indentation Work

A practical Python syntax reference for recognizing brackets, understanding colons, and using indentation to define code blocks.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python uses punctuation and indentation together to show how code is grouped. Parentheses, square brackets, and curly braces have different common roles, but context matters; a colon can introduce a code block or separate a dictionary key from its value. This guide is a quick reference for programmers learning Python syntax.

What do the brackets mean in Python?

The three delimiter pairs—(), [], and {}—help group expressions and define data structures. Their exact role depends on where they appear.

As an Amazon Associate I earn from qualifying purchases.

Delimiter Common roles Example
Parentheses () Group an expression, mark a function call, or appear in tuple and generator-expression syntax. print(value) calls a function; (a + b) * c groups an expression.
Square brackets [] Define a list, appear in a list comprehension, or select an item or slice. colors = ["red", "blue"]; colors[0] selects an item.
Curly braces {} Define a dictionary or set. A dictionary contains key:value pairs; a set contains values. {"mode": "quick"} is a dictionary; {"red", "blue"} is a set.

The empty curly-brace expression {} creates an empty dictionary, not an empty set. The bracket shape is a useful clue, but it does not by itself tell you every syntactic role.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Parentheses do not always make a tuple

A comma, not merely a pair of parentheses, makes a non-empty tuple. For example, ("x") is a grouped string expression, while ("x",) is a one-item tuple. The empty tuple is the exception: () creates one without a comma.

Commas separate items

Commas separate elements in lists, dictionary displays, and other collection syntax. They are also essential to forming non-empty tuples. For example, point = (3, 5) is a tuple because it contains a comma.

Why do I need a colon after an if statement?

A colon at the end of a compound-statement header introduces its suite—the statements controlled by that header. This applies to headers such as if, for, while, and def:

if ready:
    print("Go")

The colon inside a dictionary display has a different job: it separates a key from its value, as in {"mode": "quick"}. A colon also appears in slice syntax, for example items[1:3]. Read it in context rather than assigning one meaning to every colon.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why is indentation important in Python?

Leading whitespace determines the indentation level of a logical line. Python uses changes in that level to mark where a block begins and ends: an increase starts an indented block, and returning to an earlier level ends it. A dedent must align with a previously used indentation level.

Use one consistent indentation style throughout a file. Python expands tabs to tab stops when calculating indentation, and inconsistent mixtures of tabs and spaces can raise TabError. A mixed file does not necessarily fail in every case, but avoiding the mixture prevents ambiguous indentation.

How do brackets let Python code continue across lines?

When an expression is inside a matched pair of parentheses, square brackets, or curly braces, it can continue across physical lines without a backslash. The opening and closing delimiters must match; this rule does not make arbitrary line breaks valid.

if ready:
    items = [
        "alpha",
        "beta",
    ]
    settings = {
        "mode": "quick",
        "count": 2,
    }
  • if ready: ends a compound-statement header and introduces its suite.
  • The indented assignments belong to that suite.
  • Square brackets enclose the list; curly braces enclose dictionary key:value pairs.
  • The open collection delimiters allow the values to wrap onto additional lines without backslashes.

How to read common Python punctuation at a glance

  • Indentation: establishes block structure; a deeper level begins a block and a dedent ends it.
  • Colon after a compound header: introduces the statements in its suite.
  • Colon inside a dictionary display: separates a key from its value.
  • Parentheses: may group expressions, delimit calls, or participate in tuple syntax; check for a comma before deciding an expression is a tuple.
  • Square brackets: may enclose a list or be used for indexing and slicing.
  • Curly braces: enclose a set or dictionary display; {} is an empty dictionary.
  • Comma: separates collection items and forms non-empty tuples.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Where to learn more

The official Python Tutorial is written for programmers who are new to Python, rather than people new to programming. It provides further study, and its examples are self-contained; the tutorial can also be read offline. A beginner Python programming book or Python syntax reference book is an optional alternative if you prefer a physical reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For precise definitions, consult the Python 3.14.8 lexical analysis reference, the Python 3.14.7 compound statements reference, and the Python 3.14.7 expressions reference. These versioned documentation pages describe the language rules; version numbers may change over time.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.