+ 1

why the above variable is ignored in below code

What is the output of this code? >>> spam = 2 >>> eggs = 3 >>> del spam >>> eggs = 4 >>> spam = 5 >>> print(spam * eggs) why the output is 20 and not 15?

17th Feb 2019, 10:42 AM
Dee Pan Kar
Dee Pan Kar - avatar
2 odpowiedzi
+ 11
Dee Pan Kar it works like this way #First spam has initiated with 2 and eggs with 3 >>> spam = 2 >>> eggs = 3 #here spam is deleted by below statement >>> del spam #so spam=0 #eggs as assigned 4 so new value of eggs is 4 >>> eggs = 4 //spam now assigned 5 so it changes from 0 to 5 >>> spam = 5 #this will print multiply of spam and eggs which is 4*5=20 >>> print(spam * eggs) So the output is 20
17th Feb 2019, 11:17 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
The value of eggs variable is changed from 3 to 4, that's why.
17th Feb 2019, 11:17 AM
Tibor Santa
Tibor Santa - avatar