Tag Archives: swap two numbers in python

Python- Swap two number

We can now start to write simple programs in Python, which is really the best way to learn a language.

An easy program to swap two numbers. Python has a simple construct which enables to easily swap two numbers.

 

x = 10
y = 15

x,y=y,x

print(‘The value of x after swapping: {}’,format(x))
print(‘The value of y after swapping: {}’,format(y))

The output of the above program:

The value of x after swapping: {} 15
The value of y after swapping: {} 10
>>>