0

x,x = y,y

x=1 y4 x,x = y,y print(x+y) Can someone explain this?

7th Feb 2017, 2:21 PM
Febiana Nur Ramdani
Febiana Nur Ramdani - avatar
3 Answers
+ 2
The output is: name 'y4' is not defined ... because on second line you must probably write y=4 ^^ After having correted it, the output is '8' because on third line you assign the value of y to x twice ( one first time, and another with the same statement ), so x==4 and also y, and on last line you print the sum of x and y == 4+4 == 8 :P
8th Feb 2017, 8:47 AM
visph
visph - avatar
+ 1
your code shouldn't work. however if you want to understand what a,b=b,a means check this exemple : a=1 b=2 a,b=b,a in this exemple 'a' will be equal to 2 and 'b' will be equal to 1. name,family,age='Gandalf','Grey',572 is the same as : name="Gandalf" family="Grey" age=572
7th Feb 2017, 5:09 PM
ramzi
ramzi - avatar
0
So what's the output? cause i got that code from challenge so i dont know the right answer
8th Feb 2017, 3:39 AM
Febiana Nur Ramdani
Febiana Nur Ramdani - avatar