+ 1
what does * mean in front of a variable?
Hello, I don't understand the following code whose output is 112133 especially what the asterisk means...... x = (1,2,3) print(*x, sep='1', end='3') could anyone explain a little?
2 Respuestas
+ 4
* before variable is for "unpacking". It just prints all values in container with a space between them.
With that print call, you add a seperator. So instead of being seperated by spaces, the unpacked tuple is seperated by 1's. And of course you use the end parameter to end the print statement with 3.
unpacked:
1 2 3
unpacked with 1 as seperator
11213
then to end it all with 3
112133
+ 3
Read through this Sololearn tutorial about Tuple Unpacking, then run the code below for an example
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2485/?ref=app
a, b, *c, d = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(a)
print(b)
print(c)
print(*c, sep='1')
print(d)