Swap two variables (or more)

Find quick help here to get you started with Hollywood
Post Reply
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Swap two variables (or more)

Post by lazi »

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