Python Swap Two Variables Without Temp Variable

By | July 26, 2019

Python Swap Two Variables Without Third – This Python programmin tutorial explains the Python Swap Two Vaibles Without Third Variable progrm.

 

The Source code of Python Swap Two Variables Without Third variable program

The Source code of Python Swap Two Variables Without Third variable program

# 

Write a Python program to swap
# the values of two variables without
# using a third variable

# Author: www.EasyCodeBook.com (c)

num1= int(input('Enter 

The value of num1 Variable:'))
num2= int(input('Enter 

The value of num1 Variable:'))

print('Before sawapping the two 

variables:')
print('num1=',num1,'num2=',num2)

num1, num2 = num2, num1

print('After sawapping the two 

variables:')
print('num1=',num1,'num2=',num2)

The output of the Python Swap variables program

Enter The value of num1 Variable:10
Enter The value of num1 Variable:10000
Before sawapping the two variables:
num1= 10 num2= 10000
After sawapping the two variables:
num1= 10000 num2= 10

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *