Open In App

Remove Square Brackets from List - Python

Last Updated : 01 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

When printing a list in Python, it usually shows square brackets []. If you want to display the list elements without brackets, you need to format the output.

Example:

Input: [2,3,4,5]

Output: 2,3,4,5

Let’s explore different ways to remove square brackets when printing a list.

Using map() and join() methods

map() converts each item to a string and join() combines them into one clean string without brackets. This method is fast, readable and commonly used in Python.

Python
li = [5, 6, 8, 9, 10, 21]
r = ', '.join(map(str, li))
print(r)

Output
5, 6, 8, 9, 10, 21

Explanation: map(str, li) converts each number to a string and join() combines them into one string separated by commas.

Using loops

Looping through each item in the list and adding it to a string one by one helps create a combined string without square brackets.

Python
li = [5, 6, 8, 9, 10, 21]
r = str(li[0])
for i in li[1:]:
    r += ", " + str(i)
print(r)

Output
5, 6, 8, 9, 10, 21

Explanation:

  • r = str(li[0]) initializes the string with the first list element (5), avoiding a leading comma.
  • for i in li[1:]: loops through elements from index 1, appending each with ", " separator, forming the result.

Using str() and replace() methods

Convert the list to a string using str(), then use replace() to remove the square brackets and get a clean, comma-separated string.

Python
li = [5, 6, 8, 9, 10, 21]
print(str(li).replace("[","").replace("]",""))

Output
5, 6, 8, 9, 10, 21

Explanation: str(li) converts the list to the string and .replace("[","") removes the opening bracket, while .replace("]","") removes the closing bracket, leaving just the numbers as a clean string.

Using str() + list slicing 

Converts the list to a string using str() and removes the first and last characters ([ and ]) using list slicing.

Python
li = [5, 6, 8, 9, 10, 21]
print(str(li)[1:-1])

Output
5, 6, 8, 9, 10, 21

Explanation: str(li)[1:-1] converts the list to a string and slices off the square brackets to print elements cleanly. 

Related Articles:


Article Tags :
Practice Tags :

Similar Reads