Naming values in Python is a very powerful tool. It allows you to create code that is more readable and more reusable. It also introduces a level of complexity that can make creating programs difficult if you do not understand Python's underlying memory system. This activity will explore how Python variable references affect your programs.
1: a = 1
2: b = a
3: c = a + b
4: print('a =', a)
5: print('b =', b)
6: print('c =', c)
7: a = 2
8: print('a =', a)
9: print('b =', b)
10: print('c =', c)
-
Fill in the reference diagram below to illustrate the above program's memory after line 3 is executed.
Name Space Object Space a b c What will lines 4, 5, and 6 print to the command line when they are executed?
Fill in the reference diagram below to illustrate the above program's memory after line 7 is executed.
Name Space Object Space a b c What will lines 8, 9, and 10 print to the command line when they are executed?