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
In questa pagina del sito puoi guardare il video online Python Program to Swap Two Variables della durata di ore minuti seconda in buona qualità , che l'utente ha caricato IT WORLD 01 settembre 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 19 volte e gli è piaciuto 0 spettatori. Buona visione!