Skip to content
Home » Python program to swap the numbers without using temporary variable

Python program to swap the numbers without using temporary variable

Below is the Python program to swap the numbers without using temporary variable

# to swap the values without using temp variable
a=int(input("Enter a number:"))
b=int(input("Enter another number:"))
print("Original values of a is ",a,"and b is ",b)
a=a+b
b=a-b
a=a-b
print("After swapping a is",a,"and b is",b)

Output:

Enter a number:4
Enter another number:6
Original values of a is 4 and b is 6
After swapping a is 6 and b is 4