Hayward
Hayward

Reputation: 11

Printing out double quote in Python have space

print('"',*x,'"')

Gives out

" Hello world "

I desire

"Hello world"

What should I do?

Upvotes: 1

Views: 853

Answers (2)

NixMan
NixMan

Reputation: 545

You may try the sep parameter.

print('"', *x, '"', sep = '')

Upvotes: 0

Boseong Choi
Boseong Choi

Reputation: 2596

print put spaces(' ') between each arguments. You can change that with sep= keyword argument, but then you can't have space for between x's elements. So you can add spaces manually.

x = ['Hello', 'world']

print(f'"{" ".join(x)}"')  # Python 3.6 or later only
print('"' + " ".join(x) + '"')
print('"{}"'.format(' '.join(x)))

output:

"Hello world"
"Hello world"
"Hello world"

Upvotes: 1

Related Questions