4

I'm trying to understand splat-operators in python. I have a code:

word = ['s', 't', 'a', 'c', 'k', 'o', 'v', 'e', 'r', 'f', 'l', 'o', 'w']
print(*word)

output:

s t a c k o v e r f l o w

I can't assign *word to some variable to check its type or smth else in debug. So I wounder which way print() gets the sequence of *word and if it's possible to print this word without spaces. Desirable output:

stackoverflow
Pavel Antspovich
  • 1,111
  • 1
  • 11
  • 27

2 Answers2

6

You get that result because print automatically puts spaces between the passed arguments. You need to modify the sep parameter to prevent the separation spaces from being inserted:

print(*word, sep="")  # No implicit separation space
stackoverflow
Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
1

You can pass the separator you want, in your case:

print(*word, sep="")

or do:

print(''.join(word))
Yash
  • 3,438
  • 2
  • 17
  • 33