Exercise 1 - Variable Updating
What will the following code produce?
a = 2 a = 4 a = 6 print(a + a + a)
Hints: Python reads and executes scripts from top to bottom
Answer:
18
Explanation:
The script would output 18 in the command line. Below is the explanation. Since Python reads and executes scripts from top to bottom, variable a will be updated in every line until line 3 where a finally gets the value of 6 . Then the print function prints out 6 + 6 + 6 which is 18 .