Swap two variables (or more)

Find quick help here to get you started with Hollywood
Post Reply
User avatar
lazi
Posts: 286
Joined: Fri Feb 25, 2011 12:08 am

Swap two variables (or more)

Post by lazi » Tue Oct 06, 2015 11:26 pm

It is a common task to swap the values of two variables.

The basic idea is to use a third temporary variable like this:

temp=a
a=b
b=temp

I have just learned that there is a better way with multiple assign:

a,b=b,a

Simple, and clever :)
You can ofcourse use more than two variables/values.

Post Reply