Python list() Function Explained
The built-in list() function creates a new list.
Beginners usually use list() for two main reasons:
- to make an empty list
- to convert another iterable, such as a tuple, string,
range, set, or dictionary, into a list
This page explains how list() works, what it returns, and when you should use it.
Quick example
numbers = list((1, 2, 3))
letters = list("abc")
print(numbers)
print(letters)
Output:
[1, 2, 3]
['a', 'b', 'c']
Use list() to create a list from another iterable such as a tuple, string, range, set, or dictionary.
What list() does
list() is a built-in Python function.
It can:
- create a new list object
- make an empty list
- convert an iterable into a list
A list is a changeable sequence of items. If you are new to lists, see Python lists explained for beginners.
Basic syntax
There are two common forms:
list()
list(iterable)
list()makes an empty listlist(iterable)converts an iterable to a list
Common iterable values include:
- strings
- tuples
- sets
- ranges
- dictionaries
Create an empty list
Use list() with no arguments:
items = list()
print(items)
Output:
[]
This is useful when you want to build a list step by step:
items = list()
items.append("apple")
items.append("banana")
print(items)
Output:
['apple', 'banana']
You can also create an empty list with []. Both are valid.
Convert common values to a list
Tuple to list
numbers = list((1, 2, 3))
print(numbers)
Output:
[1, 2, 3]
If you also want to compare this with tuples, see Python tuple() function explained.
String to list
letters = list("cat")
print(letters)
Output:
['c', 'a', 't']
list() takes each character from the string and puts it into the new list.
Range to list
numbers = list(range(5))
print(numbers)
Output:
[0, 1, 2, 3, 4]
This is common when working with range(), especially when you want to see all the values at once.
Set to list
values = list({10, 20, 30})
print(values)
Example output:
[10, 20, 30]
This works, but set order is not guaranteed in the way beginners often expect. The items may appear in a different order.
Dictionary to list
person = {"name": "Ana", "age": 25}
result = list(person)
print(result)
Output:
['name', 'age']
When you pass a dictionary to list(), Python returns the dictionary keys.
If you need more help with dictionaries, see Python dict() function explained.
What counts as an iterable
An iterable is something Python can loop through.
Common iterables include:
- lists
- tuples
- strings
- sets
- ranges
- dictionaries
For example, this works because a string is iterable:
print(list("hi"))
Output:
['h', 'i']
But this fails because an integer is not iterable:
print(list(5))
Output:
TypeError: 'int' object is not iterable
If you want a deeper explanation, read iterators and iterable objects explained. If you hit this exact error, see how to fix TypeError: int object is not iterable.
list() makes a new list copy
If you already have a list, list(existing_list) creates a new list with the same items:
original = [1, 2, 3]
copied = list(original)
print(original)
print(copied)
print(original is copied)
Output:
[1, 2, 3]
[1, 2, 3]
False
This means copied is a different list object.
However, this is only a shallow copy. Nested items are still shared:
original = [[1, 2], [3, 4]]
copied = list(original)
copied[0].append(99)
print(original)
print(copied)
Output:
[[1, 2, 99], [3, 4]]
[[1, 2, 99], [3, 4]]
Both lists changed because the inner list was shared.
For more on this, see Python shallow copy vs deep copy explained.
Dictionary behavior
Dictionaries often confuse beginners when used with list().
Get dictionary keys
student = {"name": "Mia", "grade": "A"}
print(list(student))
Output:
['name', 'grade']
Get dictionary values
student = {"name": "Mia", "grade": "A"}
print(list(student.values()))
Output:
['Mia', 'A']
Get key-value pairs
student = {"name": "Mia", "grade": "A"}
print(list(student.items()))
Output:
[('name', 'Mia'), ('grade', 'A')]
This is helpful when you need the keys, values, or pairs in list form.
When to use list()
Use list() when:
- you need list methods like
append()orsort() - you want to convert
range()orzip()results into a visible list - another function gives you an iterable, but you need a real list
Example with zip():
names = ["Ana", "Ben"]
scores = [90, 85]
pairs = list(zip(names, scores))
print(pairs)
Output:
[('Ana', 90), ('Ben', 85)]
After you have a list, you can work with list methods such as append(). For a practical next step, see how to add an item to a list in Python.
Common beginner mistakes
Here are the most common problems with list().
Passing multiple values directly
This is wrong:
# Wrong
list(1, 2, 3)
list() accepts one iterable, not several separate values.
Use:
print(list((1, 2, 3)))
Expecting list("hello") to return "hello"
This is a common surprise:
print(list("hello"))
Output:
['h', 'e', 'l', 'l', 'o']
A string is iterable, so Python takes one character at a time.
If you want a list with one string item, write:
print(["hello"])
Assuming list(dict) returns values
This:
data = {"a": 1, "b": 2}
print(list(data))
returns the keys, not the values.
Use list(data.values()) if you want values.
Thinking list() makes a deep copy
list() copies the outer list only.
If the list contains nested mutable items, those inner items are still shared.
FAQ
What is the difference between and list()?
Both create a new empty list. [] is shorter. list() is often used when converting another iterable.
Why does list("abc") split the string into characters?
A string is iterable, so list() takes each character one at a time.
What does list() return for a dictionary?
It returns a list of the dictionary keys.
Does list() copy a list?
Yes, but it makes a shallow copy, not a deep copy.
Why does list(5) fail?
An integer is not iterable, so list() cannot loop through it.
See also
- Python lists explained for beginners
- Python range() function explained
- Python tuple() function explained
- Python dict() function explained
- Iterators and iterable objects explained
- Python shallow copy vs deep copy explained
- How to fix TypeError: int object is not iterable
- How to add an item to a list in Python