Get the App
SLTechnology News&Howtos  ›  Development  › 

How to quickly exchange variable values with python

Shulou Source: shulou.com Published: 2022-06-01 05:29:16 10月03日 Update

This article mainly shows you "python how to quickly exchange variable values", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "python how to quickly exchange variable values" this article.

Quickly exchange variable values

X, y = 1,2 x, yy = y, x

Through the above code, we can simply realize the data exchange between variables.

Because in Python, variables do not store values directly, they refer to a memory address, so when we exchange variables, we only exchange the address of the reference.

We can also read the Python source code ceval.c, where ROT_TWO, ROT_THREE, ROT_FOUR instructions can directly exchange the values of two variables, three variables, and four variables.

The above is all the content of the article "how to quickly exchange variable values in 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!

Tags: Variables values content articles addresses learning help three two between code memory just can be passed instructions data easy to understand more organization source code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB Shulou Tech Info OPPO Reno Redmi