+ 2

>>>spam=2 >>>egg=3 >>>del spam >>>spam=4 >>>egg=5 >>>print(spam*egg) output=20

plz help me I did'nt understood

25th Jul 2016, 5:46 AM
prajwal
prajwal - avatar
7 Answers
+ 21
1. you create a variable spam with initial value 2 2. you create a variable egg with initial value 3 3. you delete spam (his value is lost) 4. you create a new variable spam with value 4 5. you change the value of egg (you replace it with 5) at this step, you have spam=4, egg=5 6. you print spam*egg (=20)
25th Jul 2016, 6:14 AM
samuel delepoulle
samuel delepoulle - avatar
+ 4
no matter what you do before, last assignment to a variable is what counts. so, last assignmnet to spam is 4, last assignment to egg is 5 which then gives 4*5=20.
25th Jul 2016, 6:12 AM
RedAnt
RedAnt - avatar
+ 2
I think you got the wrong book... Dont import Cooking receipts for testing python ;)
25th Jul 2016, 8:18 AM
Andreas Kilian
Andreas Kilian - avatar
+ 1
It will take the last assigned variable because u are in interactive mode.there are two modes in phythod interactive and script mode.in script mode whole program will execute.but in interactive mode it gave you the results whose value u assinged at last of u r code
12th Aug 2016, 6:13 PM
Gulshan Kumar
Gulshan Kumar - avatar
0
to x complete?
5th Aug 2016, 12:44 PM
Tammie Younger
Tammie Younger - avatar
0
It is 20 bro
19th Feb 2020, 7:09 PM
Peter
0
20
14th Jun 2020, 8:20 AM
Emmanuel s, Brown
Emmanuel s, Brown - avatar