In This Python program we will learn swap two numbers without using temporary variable. Program Steps: Program to swap two numbers x=int(input("Enter value of first variable: x= ")) Output Enter value of first variable: x= 102 Conclusion: This way we can swap numbers without using temporary variable in python.
y=int(input("Enter value of second variable: y= "))
print(" **** before swap **** ")
print("x is:",x," y is:",y)
x=x+y
y=x-y
x=x-y
print(" **** after swap *** ")
print("x is:",x," y is:",y)
Enter value of second variable: y= 123
**** before swap ****
x is: 102 y is: 123
**** after swap ***
x is: 123 y is: 102
Article Contributed By :
|
|
|
|
1395 Views |