Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

Python - Swap 2 numbers using 3rd variable

Article:
Viewed:  883 
Posted On:  23/05/2015 22:26:08 
In this article I am going to explain how we can swap the valuesof the variables... 

 

Here I am going to explain how we can swap 2 variable value using 3rd variable.

Step 1: Open IDLE(Python GUI) in your system.

Step 2 : Type the below code and save the code Eg:- I have saved with swap name.

a = 8
b = 7

print("the value for 1st variable is",a)
print("the value for 2nd variable is",b)

d = a
a = b
b = d

print("the value after swaping 1st variable is",a)
print("the value after swaping 2nd variable is",b)

  
Step 3 :
 Open command prompt.

Step 4 : Go to the saved script folder.

Step 5 : Write python <Script name>.py  for execution.(Eg.- python swap.py)

 

1.png

Image 1.

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us