8

Ever felt like swapping variables?

a, b = b, a

It is the small things that count

Comments
  • 1
    @Flarp but that gives you table, doesnt it?
  • 1
    @Flarp what [ , ] stands for? Array I ment probably ;)
  • 0
    It creates one then destructs it.
  • 1
    @ridecar2 ++ for ES6 then. By my feelings will stay with Python.
  • 1
    Surely if the code works synchronously the variable do not swap but end the same. For example:
    a=1
    b=2
    a,b = b,a

    Gives us:

    a = b //a is now 1
    b = a //b is now also 1. Where's your 2?
  • 1
    @le-idiot oh cool. Wow, always learning!
  • 1
    @Player2 thats why I shared it. If it wouldnt work where is the fun.
  • 2
    And my bad. It swaps objects assigned to those variables, not the variables themself. Memory wise that is.
Add Comment