Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a list using splat-operator (*) without spaces

Tags:

python

splat

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
like image 873
Pavel Antspovich Avatar asked Mar 04 '23 03:03

Pavel Antspovich


1 Answers

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
like image 105
Carcigenicate Avatar answered Mar 12 '23 19:03

Carcigenicate