Python Program To Swap Two Numbers without Temporary Variable
Learn how to swap two numbers in Python without using a temporary variable in this simple and effective program, ideal for beginners at rrtutors.com
In This Python program we will learn swap two numbers without using temporary variable.
Program Steps:
- Take two numbers from the user and save them in two different variables
- Add both numbers and store the value in first number
- Substract second value from the first variable value and store it in second variable
- Now, subtract first value from the second variable and store it in first variable.
- Now print the values.
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.