+ 2

can someone please explain to me how i got this output?

x = 7 y = 5 x,y=y,x print (x,y) and then i will get : 5 7 the purpose is to switch the variables ... i did not understand how x,y=y,x switched the variables thanx ps: am a beginner i just started learning and it is my first exercise in python

19th Jun 2020, 4:02 PM
Salma
Salma - avatar
3 odpowiedzi
+ 3
You can tell this a special feature of python that old languages (sorry) lacks. What happens is, you change the value of x with the value of y snd vice versa
19th Jun 2020, 4:05 PM
Seniru
Seniru - avatar
+ 3
Salma x=7 y=5 x,y=y,x Means now the value of x is y and that of y is x...:) 7,5=5,7 which implies : now x=5 y=7
19th Jun 2020, 4:09 PM
Indira
Indira - avatar