Python List Declaration: Syntax and Examples
python list declaration: Learn how to declare lists in Python using literal syntax, the list() constructor, type hints, and comprehensions, with practical examples and...

Declaring a list in Python is one of the first operations you learn, but the choice of declaration method affects readability, type safety, and sometimes performance. This article covers the common ways to perform a python list declaration, when each is appropriate, and what to watch out for.
Declaring a List with Literal Syntax
The most direct way to declare a list is with square brackets and comma-separated values:
numbers = [1, 2, 3]
names = ["alice", "bob", "carol"]
empty = []The literal syntax is the most readable and is the idiomatic choice for a fixed, known set of elements. Because the list is constructed in a single expression, it also avoids the overhead of calling a constructor. There is no functional difference between [] and list() for an empty list, but the literal is shorter and more explicit about the intended type.
Using the list() Constructor
The list() constructor creates a list from an iterable. This is useful when you need to convert another sequence type or generate a list from a range:
chars = list("hello") # ['h', 'e', 'l', 'l', 'o']
squares = list(range(5)) # [0, 1, 2, 3, 4]The constructor also accepts no arguments, producing an empty list. In practice, you should prefer the literal [] for an empty list because it is more concise and does not require a function call. The constructor becomes necessary when the source is already an iterable, such as a tuple, set, or generator.
Declaring Lists with Type Hints
Modern Python code often uses type hints to document the expected element type. A list declaration with a type hint looks like this:
from typing import List
scores: List[int] = [95, 87, 92]In Python 3.9 and later, you can use the built-in list type directly:
scores: list[int] = [95, 87, 92]Type hints do not change runtime behavior; they are used by static type checkers and IDEs. Declaring the element type makes the code easier to maintain, especially in larger codebases where the intended shape of data is not obvious. For an empty list, you can still provide a type hint:
users: list[str] = []This signals that the list will eventually hold strings, even though it is momentarily empty.
Common Mistakes When Declaring Lists
A frequent mistake is using list as a variable name, which shadows the built-in constructor. For example:
list = [1, 2]
another_list = list(range(3)) # TypeError: 'list' object is not callableAvoid naming variables list or dict. Another mistake is confusing list multiplication with repetition. [0] * 5 creates a list with five zeros, but [[]] * 3 creates three references to the same inner list, which can lead to surprising mutations:
matrix = [[]] * 3
matrix[0].append(1)
# matrix is now [[1], [1], [1]]If you need independent inner lists, use a comprehension:
matrix = [[] for _ in range(3)]Memory and Performance Considerations
The declaration method rarely affects runtime performance for small lists, but it matters when building large lists. A list comprehension is generally faster than a for loop that repeatedly calls append because the loop overhead is reduced and the list is preallocated. For example:
# Slower
result = []
for i in range(1000):
result.append(i * 2)
# Faster
result = [i * 2 for i in range(1000)]The comprehension is also more readable. If you need to generate a list from an existing iterable, list(iterable) is the direct approach and is implemented in C, so it is efficient. For an empty list, the literal [] avoids the constructor call, but the difference is negligible.
Choosing the Right Declaration Approach
The decision depends on the source of the data and the need for type clarity. Use the literal syntax when you know the elements at write time. Use list() when you have an iterable that needs conversion. Use type hints whenever the list is part of a public API or a data structure that crosses module boundaries. For empty lists, prefer [] unless you also need a type hint, in which case [] with a hint is still the clearest option.
The table below summarizes the main declaration patterns:
| Pattern | Use case | Example |
|---|---|---|
[a, b, c] | Fixed known elements | [1, 2, 3] |
list(iterable) | Convert an iterable | list(range(5)) |
[] | Empty list | [] |
list[int] | Type-hinted list (Python 3.9+) | scores: list[int] = [] |
[expr for x in it] | Build from a transformation | [x**2 for x in range(5)] |
Choose the approach that makes the code's intent clear. Overusing the constructor for a literal list adds noise, while ignoring type hints in a large codebase can make refactoring harder.
Try matching browser tools
All toolsSmall utilities that fit Python work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Python guides
All Python guidesPython iter(): How the Built-in Function Works
Explains Python's iter() built-in: how it creates iterators, the two-argument sentinel form, custom iterator classes, and common edge cases.
Python Pika: Queues, Exchanges, Routing Keys, and Acknowledgements
Learn how to use Python's Pika client with RabbitMQ: declare queues and exchanges, publish with routing keys, consume messages, and handle acknowledgements reliably.
Python Kafka: kafka-python vs Confluent Client
python kafka python vs confluent kafka: Compare kafka-python and Confluent Kafka Python clients: API differences, performance, feature coverage, and when to choose eac...
Python Kafka Offsets, Partitions, and Manual Commits
Learn how Kafka offsets and partitions work and how to manually commit offsets in Python consumers with kafka-python and confluent-kafka. Covers sync vs async commits, rebalances, and seeking.
More in Python
All Python guidesThe guides filed next to this one in Python, in library order.