+ 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?
2 ответов
+ 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
+ 6
The value of eggs variable is changed from 3 to 4, that's why.