- 1

Python

Çan someone tell me how the answer to this Is 20? >>>spam=2 >>>eggs=3 >>>del spam >>>spam=4 >>>eggs=5

2nd Jul 2019, 4:46 AM
Aru
7 odpowiedzi
+ 1
With spam = 4 you give it a new value that would overwrite the previous 2 even if you didnt delete it before, same as eggs, it gets a new value at the end. So even with just the last two lines you would already get 20. spam = 4 eggs = 5 result = spam*eggs print(result) //20
2nd Jul 2019, 5:36 AM
Sohcahtoa
Sohcahtoa - avatar
+ 1
Im assuming they said spam*eggs afterward?
2nd Jul 2019, 5:13 AM
Trigger
Trigger - avatar
+ 1
You basically just declared some variables, the only way you can get 20 from this is if you multiply spam and eggs and print the result.
2nd Jul 2019, 5:15 AM
Sohcahtoa
Sohcahtoa - avatar
+ 1
It removes the value of the variable spam so if you tried to print it, it would throw an exeption saying spam is not defined.
2nd Jul 2019, 5:25 AM
Sohcahtoa
Sohcahtoa - avatar
2nd Jul 2019, 5:19 AM
Aru
0
Also what does delspam indicate?
2nd Jul 2019, 5:19 AM
Aru
0
Sohcahtoa so does that mean that it deletes the previous value? and thats why the answer of spam*eggs is 20?
2nd Jul 2019, 5:32 AM
Aru