A
A
Alan Gibizov2020-07-05 22:27:13
Python
Alan Gibizov, 2020-07-05 22:27:13

How does print(*x + y) work?

Good afternoon!
Studying Lutz and experimenting on his advice, including unpacking through an asterisk, I discovered a strange construction, and I don’t quite understand how it works and why?
Namely:

x = (1, 2, 3)
y = (4, 5, 6)
print(*x + y)

More precisely, I suspect that x and y are added first, and then the total is unpacked. But why does it work the way it does? What rule makes tuple addition work first, and then unpacking?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2020-07-06
@phaggi

Tuple addition rule) x + y is essentially a new tuple that is unpacked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question