Reputation:
Ok so I have been coding Python and when I run this code
names = ["Harry", " Ron", "Hermione"]
print(names)
# output: ['Harry', ' Ron', 'Hermione']
How do I make it so it doesn't have the [] and the ' '. Thanks!
Upvotes: 0
Views: 56
Reputation: 1247
print(', '.join([n.strip() for n in names]))
or (tks to @Ryan Haining)
print(*[n.strip() for n in names])
Upvotes: 0
Reputation: 4137
Two ways come to mind if you want to maintain the comma separator:
print(*names,sep=",")
or
print(','.join(names))
Upvotes: 1
Reputation: 3780
Depending upon you want the output to be, you can use
print(*names,sep=' ')
by default sep value is ' '. If you want to print all elements in new line then pass '\n' as sep.
Upvotes: 1
Reputation: 74
This should do it
names = ["Harry", " Ron", "Hermione"]
for name in names:
print(name, end=" ")
Upvotes: 0