CODEBREAK
LEARNING LIBRARY / PYTHON FUNDAMENTALS
Return to the investigation
REFERENCE LESSON 001 · READ ANYTIME

The Python Symbol Field Guide

What do (), [], {}, single quotes and double quotes actually mean? This guide explains their jobs using unrelated examples. No investigation solutions are included.

( )

Parentheses: call or group

Use parentheses to call a function, supply its inputs (arguments), define function parameters, or control the order of arithmetic.

print("Welcome")
len(["red", "blue"])
total = (4 + 2) * 3

def greet(person):
    print("Hello", person)

greet("Sam")
A function's name without () refers to the function itself. Adding () calls it. The parentheses are not optional when you want the function to run.
[ ]

Square brackets: lists and lookups

Use square brackets to create a list, look up an item by position, or access a value in a dictionary by its key.

cities = ["Denver", "Tampa"]
print(cities[0])

device = {"model": "M3", "power": 80}
print(device["power"])
List positions start at zero. In a dictionary, the value inside [ ] is the key you're looking for. A key such as "power" is text and needs quotes.
{ }

Curly braces: dictionaries and sets

Use curly braces to create a dictionary (keys and values separated by colons) or a set of unique values.

book = {"title": "Dune", "pages": 412}
colors = {"red", "blue", "green"}

print(book["pages"])
print(len(colors))
{} by itself creates an empty dictionary, not an empty set. For an empty set, use set(). In Python, curly braces do not mark the beginning and end of an if or for block.
' '   " "

Quotes: text values

Single quotes and double quotes both create strings (text). You may choose either for ordinary text, but the opening and closing quotes must match.

animal = 'otter'
planet = "Mars"
sentence = "It's raining"
another = 'She said "hello"'

print(animal)
animal refers to a variable; "animal" is literally the word animal. Quotes matter because they tell Python whether you mean text or a variable name.

Colon :, commas ,, and indentation

A colon starts an indented block after statements like if, for, and def. A colon also separates a dictionary key from its value. Commas separate items or function arguments.

weather = {"city": "Boston", "temp": 67}

for item in ["map", "compass"]:
    if item == "map":
        print("Pack:", item)

print("Packing finished")

The indented lines belong to the loop or condition. The final line is outside those blocks and runs once after the loop.

Quick comparison

SymbolTypical purposeQuestion to ask yourself
( )Call a function / group expressionsAm I asking Python to run something?
[ ]Make a list / retrieve an itemAm I storing a sequence or looking up a value?
{ }Create a dictionary or setAm I grouping named fields or unique values?
' ' / " "Write textDo I mean the actual word, rather than a variable?
:Begin code block / separate key and valueAm I starting a block or defining a dictionary field?
SELF-CHECK · NO MISSION SPOILERS

Test your understanding

Try to answer these before opening the explanations.

1. Which symbol retrieves a dictionary field?

Square brackets: settings["volume"]. The braces create the dictionary; the square brackets retrieve a value.

2. Why does print("city") differ from print(city)?

The quoted form prints the text city. The unquoted form refers to a variable named city, which must have been defined.

3. What does for pet in pets: need below it?

At least one indented statement forming the loop body. The colon opens the block.

4. What does () after a function name do?

It calls that function, optionally passing arguments between the parentheses.

CODEBREAK / Current & Craft · This is educational reference material, not a game answer key. Return to your case