Write a Program to Swap Two Numbers Without using Third Variable in Python 3
In This Post We Learn How to Exchange the Value of Two Numbers Without Using Temporary Variable in Python 3 Programming
Program Code Example:
a = 10
b = 5
print("Before Swap")
print("a:", a, " b:", b)
a = a+b # a = 10 +
5 , a = 15
b = a-b # b =
15-5 , b = 10
a = a-b # a = 15-10
, a = 5
print("After Swap")
print("a:", a, " b:", b)
Output:
Post a Comment