Header Ads

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:

swap,number,swap two number,swap two number without using third number,swap two number,swap two number without using third variable,









Recommended Post:

Python 3 Program to Swap First Value with Last Value Value in List


No comments

Powered by Blogger.