Difference Between {} and [] in Python

When I build a small reporting script, I often need two very different things: a sequence of report rows and a quick way to look up details by an ID. Python uses [] for one of those jobs and {} for the other, so choosing the wrong brackets can cause confusing errors later.

The difference between {} and [] in Python looks small at first. But these symbols create different data structures, store data differently, and support different operations. Once you understand the pattern, your code becomes much easier to read and maintain.

This comparison guide breaks down exactly when to use curly braces and square brackets, with practical examples from a simple sales-report automation script.

Difference Between {} and [] in Python at a Glance

Here is the quickest way to remember the difference:

SymbolCreatesBest used forExample
[]ListOrdered items that can repeat["North", "South", "East"]
{}DictionaryKey-value data for fast lookup{"region": "North", "sales": 12500}
{}SetUnique values only{"North", "South", "East"}
[]Indexing and slicingAccessing parts of lists, strings, tuples, and dictionariesregions[0]

The tricky part is that {} has two meanings. It creates a dictionary when it contains key: value pairs. It creates a set when it contains plain values without colons.

For a broader beginner-level comparison, see this guide on lists, tuples, sets, and dictionaries in Python.

What [] Means in Python

Square brackets usually create a list. A list is an ordered, changeable collection of items. It works well when your reporting script needs to preserve the order of records, process rows one by one, or allow duplicate values.

For example, imagine a script that stores daily sales figures:

daily_sales = [12500, 9800, 12500, 14300]

print(daily_sales)
print(daily_sales[0])

Output:

[12500, 9800, 12500, 14300]
12500

You can refer to the screenshot below to see the output.

C:\Users\GradyArchie\Downloads\images\Difference Between {} and [] Python.jpg

This code creates a list with four numbers. The value 12500 appears twice because lists allow duplicates. The expression daily_sales[0] uses square brackets again, but this time it accesses the first item.

Python starts list positions at zero, not one. So index 0 means the first item, index 1 means the second item, and so on.

Lists keep order and allow changes

In automation scripts, I use lists when I need to collect items in the same sequence that Python receives them. For example, you may read transaction rows from a CSV file and add valid records to a list.

regions = ["North", "South", "East"]

regions.append("West")
regions[1] = "Central"

print(regions)

Output:

['North', 'Central', 'East', 'West']

You can refer to the screenshot below to see the output.

Python Difference Between {} and []

The append() method adds an item to the end of the list. The assignment regions[1] = "Central" replaces the second item. This ability to update values makes lists useful for tasks, report rows, filenames, and API results.

If you need more practice with list operations, this tutorial explains how to add elements to an empty Python list.

Square brackets also access dictionary values

You also use [] to retrieve a value from a dictionary. This is an important detail because {} and [] often work together.

report = {
"region": "North",
"sales": 12500,
"target": 10000
}

print(report["sales"])

Output:

12500

The curly braces create the dictionary. The square brackets access the value stored under the "sales" key.

This syntax makes dictionaries useful when each value needs a meaningful label. You can learn more about checking safely for a key with how to check if a key exists in a Python dictionary.

What {} Means in Python

Curly braces create either a dictionary or a set. Python decides which one you mean from the content inside the braces.

Use curly braces with key: value pairs for a dictionary:

sales_by_region = {
"North": 12500,
"South": 9800,
"East": 14300
}

print(sales_by_region["East"])

Output:

14300

You can refer to the screenshot below to see the output.

Difference Between {} and [] in Python

A dictionary stores related information as a key and a value. Here, each region name is a key, and its sales amount is the matching value. This structure is ideal when your script needs to find a value by name instead of by position.

Dictionaries use keys, not positions

A dictionary does not work like a list. You cannot use sales_by_region[0] to get the first entry because dictionaries use keys.

sales_by_region = {
"North": 12500,
"South": 9800
}

print(sales_by_region["North"])

The code retrieves the sales value through the "North" key. This is clearer than remembering that a region sits at position zero or one.

In real scripts, dictionaries often represent JSON responses, configuration values, employee records, and grouped report data. See how to create a dictionary from two lists in Python if you need to build dictionary data dynamically.

Curly braces can also create a set

A set stores unique values. Unlike a list, it automatically removes duplicates. Use a set when your script only cares about distinct values, such as unique regions found in a sales file.

regions = {"North", "South", "East", "North"}

print(regions)

Possible output:

{'East', 'North', 'South'}

The repeated "North" value appears only once. Sets do not preserve a fixed position that you should rely on, so you cannot access set items with an index like regions[0].

Pro Tip: I’ve found that lists are usually the safest starting point for imported rows. Switch to a set only when duplicates truly have no meaning, because a set removes duplicates without warning.

Difference Between {} and [] in Python: A Practical Example

Let’s combine lists, dictionaries, and sets in one small reporting script. Imagine that a local Python script reads sales records and needs to calculate total sales by region.

sales_records = [
{"region": "North", "amount": 12500},
{"region": "South", "amount": 9800},
{"region": "North", "amount": 7600},
{"region": "East", "amount": 14300}
]

sales_totals = {}
unique_regions = set()

for record in sales_records:
region = record["region"]
amount = record["amount"]

unique_regions.add(region)
sales_totals[region] = sales_totals.get(region, 0) + amount

print(sales_totals)
print(unique_regions)

Output:

{'North': 20100, 'South': 9800, 'East': 14300}
{'North', 'South', 'East'}

This example uses each structure for the job it handles best:

  • sales_records uses [] because the script needs an ordered collection of records.
  • Each record uses {} because "region" and "amount" are labeled pieces of data.
  • sales_totals starts as {} because it stores one total against each region name.
  • unique_regions uses set() because duplicate region names should appear once.

The get() method matters here. sales_totals.get(region, 0) returns the existing total for a region. If Python does not find that region yet, it returns 0 instead. This prevents a KeyError, which is an error Python raises when code asks for a missing dictionary key.

For another useful dictionary pattern, explore how to update values in a Python dictionary.

Empty {} and Empty ]

Empty brackets have a special rule that catches many beginners.

empty_list = []
empty_dictionary = {}
empty_set = set()

print(type(empty_list))
print(type(empty_dictionary))
print(type(empty_set))

Output:

<class 'list'>
<class 'dict'>
<class 'set'>

An empty pair of square brackets, [], creates an empty list. An empty pair of curly braces, {}, creates an empty dictionary, not an empty set.

Python needs set() for an empty set because {} already has a clear meaning: an empty dictionary.

When Should You Use Each One?

Choose a list when order, duplicates, or numeric positions matter. Choose a dictionary when each value needs a descriptive key. Choose a set when unique values matter more than order.

# Use a list for ordered report filenames
report_files = ["january.csv", "february.csv", "march.csv"]

# Use a dictionary for named report settings
settings = {
"output_folder": "reports",
"include_summary": True
}

# Use a set for unique email domains
domains = {"example.com", "contoso.com", "example.com"}

This code reflects a common automation workflow. A list keeps files in processing order, a dictionary holds readable configuration values, and a set removes repeated domains.

Things to Keep in Mind

  • Empty curly braces create dictionaries: Use set() rather than {} when you need an empty set.
  • Lists allow duplicates: Use [] when repeated values carry meaning, such as duplicate transactions or repeated log entries.
  • Sets remove duplicates automatically: Do not use a set if your script must preserve every original record.
  • Dictionary keys must be unique: Adding the same key again replaces its old value instead of creating another entry.
  • Use safe dictionary lookups: Prefer data.get("key") when a key may not exist, especially with external JSON or user input.
  • Avoid relying on set order: Sets work well for membership checks and uniqueness, but not for position-based processing.

Frequently Asked Questions

What is the difference between [] and {} in Python?

Square brackets [] create lists, while curly braces {} create dictionaries or sets. Lists store ordered items, dictionaries store key-value pairs, and sets store unique values.

Does {} create a list in Python?

No. Curly braces do not create a list. Use square brackets [] to create a list, such as names = ["Asha", "Ravi"].

Why does {} create a dictionary instead of a set?

Python uses curly braces for both dictionaries and sets. An empty {} has no values or key-value pairs to identify a set, so Python defines it as an empty dictionary. Use set() for an empty set.

Can I access a set with square brackets in Python?

No. Sets do not support indexing, so my_set[0] raises a TypeError. Convert the set to a list first only if you truly need indexed access.

Can a Python dictionary have duplicate keys?

No. Every dictionary key must be unique. If you assign a new value to an existing key, Python replaces the old value.

Should I use a list or dictionary for JSON data?

Use a dictionary for one JSON object with named fields, such as a customer record. Use a list when JSON contains multiple objects, such as a list of customer records. Many API responses combine both structures.

The difference between {} and [] in Python comes down to how you need to store and retrieve data. Start with lists for ordered collections, dictionaries for labeled data, and sets for unique values, then let your script’s real requirement guide the choice. I hope you found this article helpful.

You May Also Like

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.