Open In App

Ways to Print List without Quotes - Python

Last Updated : 04 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The task of printing a list without quotes in Python involves displaying the elements of the list without the default string representation which includes quotes around string elements. For example, given the list a = ['a', 'b', 'c', 'd'], the goal is to print the list in the format [a, b, c, d] without quotes.

Using join()

join() concatenates all elements of an iterable into a single string, separated by a specified delimiter. It works efficiently with lists of strings and helps format the output without quotes.

Python
a = ['a', 'b', 'c', 'd']
print('[%s]' % ', '.join(a))

Output
[a, b, c, d]

Explanation :print('[%s]' % ', '.join(a)) uses old-style string formatting where %s is a placeholder for a string and ', '.join(a) joins list elements with commas and spaces, replacing %s inside the brackets.

Using unpacking

Unpacking operator * expands the elements of a list, allowing them to be printed individually as separate arguments in the print() . This method is concise and works well with both strings and mixed data types.

Python
a = ['a', 'b', 'c', 'd']
print('[', end=' ')
print(*a, sep=', ', end=' ')
print(']')

Output
[ a, b, c, d ]

Explanation :print('[', end=' ') prints an opening bracket [ without moving to a new line. Then, print(*a, sep=', ', end=' ') unpacks the list a and prints each element with a comma and space between them. Finally, print(']') prints the closing bracket ].

Using format

format() allows inserting values into placeholders {} within a string. It’s useful for adding additional formatting, combining static text with dynamic data and structuring the output neatly.

Python
a = ['a', 'b', 'c', 'd']
print('[{}]'.format(', '.join(a))) 

Output
[a, b, c, d]

Explanation: print('[{}]'.format(', '.join(a))) joins the list elements with commas and spaces, then inserts the result into the {} placeholder inside the brackets .

Using for loop

For loop iterates over each element of the list, providing complete control over how elements are printed. It’s highly flexible, especially for adding custom separators, formatting, or handling complex data structures.

Python
a = ['a', 'b', 'c', 'd']

print('[', end='')
for i in range(len(a)):
    print(a[i], end=', ' if i < len(a)-1 else '')
print(']')

Output
[a, b, c, d]

Explanation: For loop iterates through the list and prints each element, adding a comma after each element except the last one checked using i < len(a)-1 . Finally, it prints the closing bracket ].


Next Article
Practice Tags :

Similar Reads