Swap two variables (or more)

Find quick help here to get you started with Hollywood

Swap two variables (or more)

Postby 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.
User avatar
lazi
 
Posts: 268
Joined: Fri Feb 25, 2011 12:08 am

Return to Newbie questions

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron