Basic Python Program to Swap Two Variables

 Basic python program to swap two variables


Learn python online. Python Program to Swap Numbers

Program Explanation:

We are writing the python program to swap two variables in a simple method

-> Swapping can be simply said to be interchanging the numbers from it original place to another place 

-> The values will be changed during the swapping just the place of the value will change from its normal place 

-> Taken two values X = 5  ( #before swapping) 
                                 Y = 4
-> then after swapping the values will be
     X = 4
     Y = 5

Source code:

# Python swap program   

x = input('Enter value of x: ')  

y = input('Enter value of y: ')  

# create a temporary variable and swap the values  
temp = x  
x = y  
y = temp  

print('The value of x after swapping: {}'.format(x))  
print('The value of y after swapping: {}'.format(y))  


Learn python Language Full, Learn basics of python

copyrights: Java point

Post a Comment

Previous Post Next Post