How to Print a List Without Brackets in Python
When displaying list data to users: whether in console output, reports, log files, or user interfaces: Python's default list representation with square brackets and quotes is often undesirable. Instead of seeing [1, 2, 3, 4, 5], you typically want a cleaner format like 1 2 3 4 5 or 1, 2, 3, 4, 5.
In this guide, you'll learn multiple methods to print a list without brackets in Python, understand the differences between each approach, and choose the best one for your specific use case.
Using the * Unpacking Operator (Recommended)
The simplest and most Pythonic way to print a list without brackets is using the * (unpacking) operator inside the print() function. It passes each list element as a separate argument to print():
li = [1, 2, 3, 4, 5]
print(*li)
Output:
1 2 3 4 5
By default, print() separates arguments with a space. You can customize the separator using the sep parameter:
li = [1, 2, 3, 4, 5]
# Comma-separated
print(*li, sep=', ')
# Dash-separated
print(*li, sep=' - ')
# No separator
print(*li, sep='')
Output:
1, 2, 3, 4, 5
1 - 2 - 3 - 4 - 5
12345
The * unpacking operator works with any data type: integers, floats, strings, or mixed types: without needing to convert elements to strings first. This makes it the most versatile approach.
Using the join() Method
The str.join() method concatenates list elements into a single string with a specified delimiter between them:
li = ['apple', 'banana', 'cherry']
print(', '.join(li))
Output:
apple, banana, cherry
You can use any delimiter:
li = ['apple', 'banana', 'cherry']
print(' | '.join(li)) # Pipe-separated
print(' -> '.join(li)) # Arrow-separated
print('\n'.join(li)) # Each element on a new line
Output:
apple | banana | cherry
apple -> banana -> cherry
apple
banana
cherry
Handling Non-String Elements
The join() method only works with strings. If your list contains integers or other types, you must convert them first:
li = [1, 2, 3, 4, 5]
# ❌ This raises a TypeError
try:
print(', '.join(li))
except TypeError as e:
print(f"Error: {e}")
Output:
Error: sequence item 0: expected str instance, int found
Fix: Use map() or a generator expression to convert elements to strings:
li = [1, 2, 3, 4, 5]
# ✅ Using map()
print(', '.join(map(str, li)))
# ✅ Using a generator expression
print(', '.join(str(x) for x in li))
Output:
1, 2, 3, 4, 5
1, 2, 3, 4, 5
Unlike the * unpacking operator, join() gives you a string result that you can store in a variable, write to a file, or use in further string operations: not just print to the console.
Using str() with String Slicing
A quick approach is to convert the list to its string representation and then slice off the brackets:
li = [1, 2, 3, 4, 5]
print(str(li)[1:-1])
Output:
1, 2, 3, 4, 5
This works because str([1, 2, 3, 4, 5]) produces the string '[1, 2, 3, 4, 5]', and [1:-1] removes the first character ([) and the last character (]).
This method has a notable drawback with string elements: it preserves the quotes around each item:
li = ['apple', 'banana', 'cherry']
print(str(li)[1:-1])
Output:
'apple', 'banana', 'cherry'
The single quotes remain because they're part of Python's string representation. Use join() or * unpacking instead if you want clean output without quotes.
Using a for Loop
A for loop gives you the most control over formatting. Use the end parameter in print() to keep elements on the same line:
li = [1, 2, 3, 4, 5]
for item in li:
print(item, end=' ')
Output:
1 2 3 4 5
Adding a Delimiter Between Elements (Not After the Last)
A common challenge with the loop approach is avoiding a trailing delimiter after the last element:
li = [1, 2, 3, 4, 5]
# ❌ Trailing comma after the last element
for item in li:
print(item, end=', ')
Output:
1, 2, 3, 4, 5,
Fix: Use enumerate() to detect the last element:
li = [1, 2, 3, 4, 5]
for i, item in enumerate(li):
if i < len(li) - 1:
print(item, end=', ')
else:
print(item)
Output:
1, 2, 3, 4, 5
While the loop approach offers maximum control, it's more verbose. For most cases, * unpacking with sep or join() achieves the same result in a single line.
Formatting Nested Lists Without Brackets
If you have a nested list (list of lists), you may want to remove brackets at multiple levels:
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# Print each row without brackets
for row in matrix:
print(*row, sep='\t')
Output:
1 2 3
4 5 6
7 8 9
For a completely flat output:
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# Flatten and print
flat = [item for row in matrix for item in row]
print(*flat, sep=', ')
Output:
1, 2, 3, 4, 5, 6, 7, 8, 9
Comparison of Methods
| Method | Works with All Types | Custom Delimiter | Returns String | Clean String Output |
|---|---|---|---|---|
print(*li, sep=...) | ✅ | ✅ | ❌ (prints only) | ✅ |
', '.join(map(str, li)) | ✅ (with map) | ✅ | ✅ | ✅ |
str(li)[1:-1] | ✅ | ❌ (always , ) | ✅ | ❌ (keeps quotes on strings) |
for loop with end | ✅ | ✅ | ❌ (prints only) | ✅ |
Summary
To print a list without brackets in Python:
- Use
print(*li)for the simplest, most Pythonic solution: customize spacing with thesepparameter. - Use
', '.join(map(str, li))when you need a string result for storage, file writing, or further processing. - Use
str(li)[1:-1]for a quick one-liner, but be aware it preserves quotes around string elements. - Use a
forloop when you need maximum control over formatting, such as conditional delimiters or custom logic per element.
For most use cases, the * unpacking operator is the recommended approach due to its simplicity, readability, and compatibility with all data types.