97% Of Python Coders Don’t Know This

I can guarantee 97% of you do not know this about Python.

Say, I assign 10 to variable a and 20 to variable b.

Now, if I wanted to swap these two values, I would normally use a third variable.

But in Python I can use tuple unpacking so I don’t have to use a temporary variable.

All I have to do is type a, b = b, a.

Now watch what happens when I print the values.

Source: https://www.youtube.com/watch?v=_z8FMyiVaVM

Leave a Reply

Your email address will not be published. Required fields are marked *