0

I am a beginner, learning python language.I was given a problem of swapping 2 variables without using a third variable. Didn't understand why these variables simply swapped when assigned in this way seperated by a comma

I have googled the reason why this happens but have not come across a detailed satisfactory answer.

a=12 b="Stirling"

print("value of a and b is :\n",a,b)

a,b=b,a

print("After swap value of a and b is :\n",a,b)

I expected an error But output is the 2 variables are simply swapped.

Kunal B
  • 45
  • 5
  • What error did you expect? And why? –  Oct 19 '19 at 15:03
  • 1
    You can have a look at https://stackoverflow.com/questions/45574730/meaning-of-comma-operator-in-python –  Oct 19 '19 at 15:05

0 Answers0