Chapter 36 Tips and Tricks with Subprograms
36.1 Can Two Subprograms use Variables of the Same Name?
Each subprogram uses its own memory space to hold the values of its variables. Even the main code has its own memory space! This means that you can have a variable named test in main code, another variable named test in a subprogram, and yet another variable named test in another subprogram. Pay attention! Those three variables are three completely different variables, in different memory locations, and they can hold completely different values.
As you can see in the program that follows, there are three variables named test in three different memory locations and each one of them holds a completely different value. The trace table below can help ...
Get Python and Algorithmic Thinking for the Complete Beginner now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.