Python
lists
square brackets
parentheses
programming basics

What's the difference between lists enclosed by square brackets and parentheses in Python?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Python, square brackets and parentheses do not mean the same thing. Square brackets usually create a list, while parentheses usually create a tuple or just group an expression. The difference matters because lists are mutable and tuples are not.

Square Brackets Create Lists

A list is an ordered, mutable sequence.

python
1numbers = [1, 2, 3]
2numbers.append(4)
3numbers[0] = 10
4print(numbers)

Lists are useful when the collection needs to change over time. You can append, remove, sort, and replace elements.

Because lists are mutable, they are a good fit for queues, accumulators, and data you build incrementally.

Parentheses Usually Create Tuples

A tuple is also an ordered sequence, but it is immutable.

python
1point = (3, 5)
2print(point[0])
3
4# point[0] = 10  # This would raise a TypeError

Tuples are useful when the values should stay fixed after creation, such as coordinates, RGB values, or a structured multi-value return from a function.

Immutability also makes tuples safer to share because other code cannot accidentally edit them.

The Comma Matters More Than the Parentheses

A subtle Python rule is that the comma is what really creates a tuple.

python
1single_value = (42,)
2not_a_tuple = (42)
3
4print(type(single_value))
5print(type(not_a_tuple))

(42,) is a one-element tuple. (42) is just the integer 42 wrapped in parentheses for grouping.

This is one of the most common beginner mistakes. People expect parentheses alone to force tuple creation, but Python only treats it as a tuple when there is a comma.

Parentheses Also Group Expressions

Sometimes parentheses do not create a data structure at all. They only control evaluation order.

python
result = (2 + 3) * 4
print(result)

The parentheses here are just grouping the arithmetic. There is no tuple involved.

The same is true in conditions, generator expressions passed directly into functions, and long expressions split across lines.

Lists and Tuples Behave Differently in Real Code

The difference is not just syntax. It affects how functions interact with the value.

python
1def update_scores(values):
2    values[0] = 99
3
4scores = [10, 20, 30]
5update_scores(scores)
6print(scores)

This works because lists are mutable. The same idea fails with a tuple.

python
1def try_update(values):
2    values[0] = 99
3
4coords = (10, 20, 30)
5# try_update(coords)  # This would raise a TypeError

That behavior is often the real reason to choose one over the other.

When to Choose a List

Use a list when:

  • the collection will grow or shrink
  • elements need to be replaced
  • order matters and mutation is expected
  • you want list-specific methods such as append or sort

Lists are the default choice for many day-to-day programming tasks because they are flexible.

When to Choose a Tuple

Use a tuple when:

  • the values represent a fixed record
  • you want to signal that the data should not be changed
  • the object may need to be hashable for use in a dictionary key or a set element
  • you are returning multiple related values from a function
python
1def min_max(values):
2    return min(values), max(values)
3
4result = min_max([4, 1, 9, 2])
5print(result)
6print(type(result))

Here the return value is naturally a tuple because it is a fixed pair.

Do Not Confuse Tuples With Function Calls

Parentheses are also used for function calls.

python
print("hello")

That is not a tuple either. It is just call syntax. Python reuses punctuation in several contexts, so the surrounding code matters.

Common Pitfalls

  • Assuming parentheses always create a tuple.
  • Forgetting the trailing comma in a one-element tuple.
  • Using a list when the data should be fixed and read-only.
  • Using a tuple and then trying to modify it later.
  • Confusing grouping parentheses with collection syntax.

Summary

  • Square brackets usually create lists.
  • Parentheses often create tuples, but they can also group expressions or mark function calls.
  • Lists are mutable and better for changing collections.
  • Tuples are immutable and better for fixed records.
  • For a one-element tuple, the comma is essential.

Course illustration
Course illustration

All Rights Reserved.