Back

Explore Courses Blog Tutorials Interview Questions
+9 votes
6 views
in Python by (900 points)
edited by

I have a list in Python e.g.

letters = ["t", "h", "e"]

I want to print the array in a single line without the normal " []
 

names = ["t", "h", "e"]
print (letters)

Will give the output as;

["t", "h", "e"]

That is not the format I want instead I want it to be like this;

t, h, e

Note: It must be in a single row.
 

closed

2 Answers

+12 votes
by (10.5k points)
selected by
 
Best answer

Try the code given below, all the elements will be separated with a comma.

name= [“t”,”h”,”e”]

Print ( ‘,’ .join(name))

Output:- t,h,e

0 votes
by (32.3k points)
edited by

Here is a simple solution for you, just try this:

names = ["t", "h", "e"]

print(*names, sep=", ")

The work of star(*) is to unpack the list and return every element present in the list.

You can use the following video tutorials to clear all your doubts:-

Browse Categories

...