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
>>>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s