Can someone explain to me why when I'm trying to pass unpacked data into print function using asterisk, the optional argument "end" is applied only for the last list's element, and for the rest is default (space)
l = ['a', 'b', 'c']
print(*l, end='-')
I expected a-b-c-
instead of a b c-
According to the print()
docs,
Print objects to the text stream file, separated by
sep
and followed byend
.All non-keyword arguments are converted to strings like
str()
does and written to the stream, separated bysep
and followed byend
.
The sep
argument is used to control the separator between arguments to print
. end
just controls the line terminator.
l = ['a', 'b', 'c']
print(*l, sep='-', end='-')
# a-b-c-