This python program swaps two numbers using a temporary variable. To swap numbers without using extra variable see another code below.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | num1 = 75 num2 = 42 print('Before Swapping') print('First Number:{0} '.format(num1)) print('Second Number:{0} '.format(num2)) print('\n') num1=num1+num2; num2=num1-num2; num1=num1-num2; print('After Swapping') print('First Number:{0} '.format(num1)) print('Second Number:{0} '.format(num2)) |
Output:
6-Swap-two-numbers-without-using-third-variable-in-Python
Download Swap two numbers without using third variable in Python