Reputation: 11
print('"',*x,'"')
Gives out
" Hello world "
I desire
"Hello world"
What should I do?
Upvotes: 1
Views: 853
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