Advertisement
armanhusain

Variable Swap

Jan 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. # Initial variable declaration
  2. a = 1
  3. b = 2
  4.  
  5. # printing out values before swap
  6. print("Before the swap, the value of a is", a, "and the value of b is", b)
  7.  
  8.  
  9.  
  10. # Variable swap construct. This assigns the value of b to a and the value of a to b.
  11. a, b = b, a
  12.  
  13. # printing out values after swap
  14. print("After the swap, the value of a is", a, "and the value of b is", b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement