Using temporary variable :
In this program, we use the temp variable to temporarily hold the value of x. We then put the value of y in x and later temp in y. In this way, the values get exchanged.
Without Using Temporary Variable :
In python programming, there is a simple construct to swap variables. The following code does the same as above but without the use of any temporary variable.
x,y = y,x
If the variables are both numbers, we can use arithmetic operations to do the same. It might not look intuitive at the first sight. But if you think about it, its pretty easy to figure it out.Here are a few example
Addition and Subtraction
x = x + y
y = x - y
x = x - y
Multiplication and Division
x = x * y
y = x / y
x = x / y
Auf dieser Seite können Sie das Online-Video Python Program to Swap Two Variables mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer IT WORLD 01 September 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 19 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!