How to exchange two digits on the spot by python
This article mainly shows you "how python exchanges two numbers on the spot". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "how python exchanges two numbers on the spot".
Exchange two numbers on the spot
Python provides an intuitive way to assign and exchange values on a single line. Please refer to the following example.
X, y = 10, 20print (x, y) x, y = y, xprint (x, y) # 1 (10,20) # 2 (20,10)
The assignment on the right is a new meta-multicast seed. The one on the left immediately unpacks that (unreferenced) tuple to the name and.
When the allocation is complete, the new tuple is dereferenced and marked as garbage collection. The exchange of variables also occurs at the end.
The above is all the content of the article "how to exchange two numbers on the spot by python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!