The most native approach is to store the value of one variable(say x) in a temporary variable, then assigning the variable x with the value of variable y. Finally, assign the variable y with the value of the temporary variable.
Code:
X = int( input("Please enter value for X: "))
Y = int( input("Please enter value for Y: "))
# To swap the value of two variables
# we will user third variable which is a temporary variable
temp_1 = X
X = Y
Y = temp_1
print ("The Value of X after swapping: ", X)
print ("The Value of Y after swapping: ", Y)
Output:
![](https://static.wixstatic.com/media/0f65e1_50702aeccdd14a07b4d44d7859d59d58~mv2.png/v1/fill/w_88,h_12,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/0f65e1_50702aeccdd14a07b4d44d7859d59d58~mv2.png)
Read More:
The Tech Platform