SlideShare a Scribd company logo
1 of 48
Download to read offline
russ.lavery@verizon.net 3/22/2021
1
Python Memory Management
Russ Lavery
Advanced topic
Focus will be: Vocabulary and Concepts
Background for some talks about a very common error
Knowing this lets you talk with IT
You will Not be an expert or able to solve memory problems
Memory Management in Python: Theresa Lee
https://www.youtube.com/watch?v=3pXquKQf2qk
Wesley Chun, "Python 103: Memory Model & Best Practices", PyBay2016
https://www.youtube.com/watch?v=SiXyyOA6RZg
Kavya Joshi The Memory Chronicles A Tale of Two Pythons PyCon 2017
https://www.youtube.com/watch?v=d7qEzpnkWaY
Pointers and dynamic memory - stack vs heap mycode_School
https://www.youtube.com/watch?v=_8-ht2AKyH4
Rules of behaviour in a cartoon-like, visual, format
Basic Pointers
(interning of commonly used values)
russ.lavery@verizon.net 3/22/2021
2
Python Memory Management
This is for C-python and other pythons may be different
Simple examples only
Everything in Python is an object
VarName=5
dir(VarName)
Out[14]:
['__abs__',
'__add__',
'__and__',
'__bool__',
'__ceil__',
'__class__',
'__delattr__',
'__dir__',
'__divmod__',
'__doc__',
'__eq__',
'__float__',
'__floor__',
'__floordiv__',
'__format__',
'__ge__',
'__getattribute__',
'__getnewargs__',
'__gt__',
'__hash__',
'__index__',
'__init__',
'__init_subclass__',
'to_bytes']
'__int__',
'__invert__',
'__le__',
'__lshift__',
'__lt__',
'__mod__',
'__mul__',
'__ne__',
'__neg__',
'__new__',
'__or__',
'__pos__',
'__pow__',
'__radd__',
'__rand__',
'__rdivmod__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__rfloordiv__',
'__rlshift__',
'__rmod__',
'__rmul__',
'__ror__',
'__round__',
'__rpow__',
'__rrshift__',
'__rshift__',
'__rsub__',
'__rtruediv__',
'__rxor__',
'__setattr__',
'__sizeof__',
'__str__',
'__sub__',
'__subclasshook__',
'__truediv__',
'__trunc__',
'__xor__',
'bit_length',
'conjugate',
'denominator',
'from_bytes',
'imag',
'numerator',
'real',
All variables/objects are stored in a
complicated system of pointers to
memory location.
RAM has numbered memory
locations, like lists
Sections of RAM are reserved
RAM
Code: instruction
Global Vars
Heap
Stack
100
200
300
400
500
600
700
800
900
1000
1100
1200
Often understood incompletely…
Lets see some examples
Python Memory Management
Python has some tricks that even “catch” teachers
Integers between -5 and 256 (might be expanded) are sent to pre-allocated
memory locations in RAM
NewVar1=VarName2
id(NewVar)
x=333
id(x)
140714552500752
140714552500752
140714552500752
140714552500752
140714552500752
140714552500752
VarName2
NewVar
14…0752
14…0752
14…0752
5
140714552500752
VarName1 14…0752
Changes at every call
1513644174288
1513644174288
1513644174896
Changes at every call
RAM
VarName1=5
id(VarName1)
VarName2=5
id(VarName2)
id(5)
id(5*1)
id(10/2)
id (100/20)
y=x
id(y)
z=333
id(z)
333
74288
74896
333
All 5’s go to
the same
memory
location
Beware of rules/examples
on Youtube that only show
integer values between -5
and 256
We Want General Rules of
Behavior!
russ.lavery@verizon.net 3/22/2021
3
Python Memory Management
Documents say that strings that are:
are stored in the same memory location ¯_(ツ)_/¯
CV1 = "bed"
id(CV1)
CV2 = "bed"
id(CV2)
CV1 == CV2
id(CV1) == id(CV2)
CV1 is CV2
1513661556720
1513661556720
True
True
True
CV3='bed!'
id(CV3)
CV4='bed!'
id(CV4)
1513661627696
151366171934
CV10 = "s"
1513545485040
1513550729840
1513545485040
1513546905456
less than a certain length…and
are upper/lower letters, numbers and the underscore
CV12='l'
1513546905456
1513545485232
1513545485232
1513545485232
1513545480688
s l e e p
…5040
CV 11
…9840
…9840
…5456 …5232 …5232 …0688
Strings are “container objects”
! Blocks
interning
s
e
"sleep" l
sleep
l
e
sleep
sleep
sleep
id(CV12)
id('e')
id(CV11[2])
id(CV11[3])
id(CV11[4])
sleep
id(CV10)
CV11 = "sleep"
id(CV11)
id(CV11[0])
id(CV11[1])
Start of container
== compares value equality and ‘is’ checks if
both variables refer to the same object.
Python Memory Management
Documents say that strings that are:
CharVar1 = 'Z'
1513550636976
CharVar1==CharVar3
less than a certain length
are upper/lower letters, numbers and the underscore
1513550636976
True
CharVar4= 'z'.upper()
'Z'
1513661769200
After upper-casing
Z character is in a different
memory location
CharVar1 , CharVar2
Z character in same memory locations
CharVar1 , CharVar2 & CharVar3
Z character in same memory locations
True
True
Also a Z
id(CharVar1) == id(CharVar3)
CharVar1 is CharVar3
id(CharVar1)
CharVar2 = 'Z'
id(CharVar2)
CharVar3 = CharVar2
CharVar4
id(CharVar4)
are stored in the same memory location ¯_(ツ)_/¯
russ.lavery@verizon.net 3/22/2021
4
Mutable and Immutable object
types
Python Memory Management
IMMutable (int, float, str, tuple,set) vs Mutable (list, dict)
N1= 350
print("N1 is",N1 ,"at " ,id(N1 ))
N2=N1
print("N2 is",N2 ,"at " ,id(N2 ))
N3=350
print("N3 is",N3 ,"at " ,id(N3 ))
N1 = N1+1
print("N1 is",N1 ,"at " ,id(N1 ))
print("N2 is",N2 ,"at " ,id(N2 ))
 N1 is 350 at 2208632141168
 N2 is 350 at 2208632141168
 N3 is 350 at 2208632140784
 N1 is 351 at 2208632041200
 N2 is 350 at 2208632141168
350
0784
N2 1168
N3 0784
350
1168
N1 1200
351
1200
N1 1168
 No change
Lookup table Value Storage
Breaks (erases) connection of N1 to location 1168.
Creates new N1 entries in lookup table and the value storage memory
russ.lavery@verizon.net 3/22/2021
5
Python Memory Management
IMMutable (int, float, str, tuple,set) vs Mutable (list, dict)
Strng_1 ="Kpop"
print( "Strng_1 is “ ,Strng_1 , "at " , id(Strng_1 ) )
print( "Strng_1[0] is“ ,Strng_1[0] , "at " , id(Strng_1[0] ) )
print( "Strng_1[1] is“ ,Strng_1[1] , "at " , id(Strng_1[1] ) )
print( "Strng_1[2] is“ ,Strng_1[2] , "at " , id(Strng_1[2] ) )
print( "Strng_1[3] is“ ,Strng_1[3] , "at " , id(Strng_1[3] ) )
Strng_1[1] = 'x'
Strng_1 = Strng_1.lower()
print( "Strng_1 is “ ,Strng_1 , "at " ,id(Strng_1 ) )
print( "Strng_1[0] is“ ,Strng_1[0] , "at " , id(Strng_1[0] ) )
print( "Strng_1[1] is“ ,Strng_1[1] , "at " , id(Strng_1[1] ) )
print( "Strng_1[2] is“ ,Strng_1[2] , "at " , id(Strng_1[2] ) )
print( "Strng_1[3] is“ ,Strng_1[3] , "at " , id(Strng_1[3] ) )
7792
memory loc. of container header
6656 0240 5168 0240
K p o p
 TypeError: 'str' object does not support item assignment
4304
memory loc. of container header
2608 0240 5168 0240
k p o p
Cannot change a string IN IT’S CURRENT
MEMORY LOCATION
When you change/reassign a string, the container
memory location changes
But elements might be in the same memory location
Lowercase and assign to original name
Python Memory Management
IMMutable (int, float, str, tuple,set) vs Mutable (list, dict)
''' Tuples are immutable '''
tup1 = 1,3,1
print( "tup1 is " , tup1 , "at“ , id(tup1 ) )
print( "tup1[0] is“ , tup1[0] , "at“ , id(tup1[0] ) )
print( "tup1[1] is“ , tup1[1] , "at“ , id(tup1[1] ) )
print( "tup1[2] is“ , tup1[2] , "at“ , id(tup1[2] ) )
''‘Code below fails and so people say tuples are immutable '''
tup1[1] = 123  TypeError: 'tuple' object does not support item assignment
'''however, mutable objects , in a tuple can be changed '''
2592
memory loc. of tuple header
2664 2656 2592
1 3 1
 tup1[2] is 1 at 140708655112592
 tup1 is (1, 3, 1) at 1615190232664
 tup1[0] is 1 at 140708655112592
 tup1[1] is 3 at 140708655112656
russ.lavery@verizon.net 3/22/2021
6
Python Memory Management
IMMutable (int, float, str, tuple,set) vs Mutable (list, dict)
tup2 =(1 , [ "A“ , "B“ , "C“ ] , 2)
print( "tup2 is" ,tup2 , ‘at’ , id(tup2 ))
print( "tup2[0] is“ ,tup2[0] , ‘at’ , id(tup2[0]))
print( "tup2[1] is“ ,tup2[1] , ‘at’ , id(tup2[1]))
print( "tup2[1] [0] is“ ,tup2[1][0] , ‘at’ , id(tup2[1] [0]))
tup2[0] = 9  TypeError: 'tuple' object does not support item assignment
Mutable objects , in a tuple, can be changed '''
7728
memory loc. of tuple header
7032 6744 7760
1 List 2
7728
memory loc. of list header
6744 7312 7184
A B C
We can not change a tuple element if the element is immutable…
however, mutable elements/objects , in a tuple, can be changed
A list
Python Memory Management
IMMutable (int, float, str, tuple,set) vs Mutable (list, dict)
tup2[1] = ["Pesky","Wabbit"]
tup2[1][0] = "Eah"
tup2[1][1] = [ "Pesky“ , "Wabbit“ ]
7728
memory loc. of tuple header
7032 6744 7760
1 List 2
7728
memory loc. of list header
6744 7312 7184
A B C
 TypeError: 'tuple' does not support item assignment
tup2 =(1 , [ "A“ , "B“ , "C“ ] , 2)
print( "tup2 is" ,tup2 , ‘at’ , id(tup2 ))
print( "tup2[0] is“ ,tup2[0] , ‘at’ , id(tup2[0]))
print( "tup2[1] is“ ,tup2[1] , ‘at’ , id(tup2[1]))
print( "tup2[1] [0] is“ ,tup2[1][0] , ‘at’ , id(tup2[1] [0]))
print( "tup2[1] [1] is“ ,tup2[1][1] , ‘at’ , id(tup2[1] [1]))
print( "tup2[1] [2] is“ ,tup2[1][2] , ‘at’ , id(tup2[1] [2]))
print( "tup2[2] is“ ,tup2[2] , ‘at’ , id(tup2[2]))
7728
memory loc. of tuple header
7032 6744 7760
1 List 2
7728
memory loc. of tuple header
6744 7312 7184
A B C
"Eah"
7264 2120
List
1296
memory loc. of list header
2120 2192
Pesky Wabbit
It is recursive turtles all
the way down
Mutable objects , in a tuple, can be changed '''
A list
russ.lavery@verizon.net 3/22/2021
7
Lists are Mutable, however, immutable objs. in lists are immutable at same memory location''‘
list_1 = [ 300 , 503.2 , 'pi‘ , [ 1 , 2 , 3 ] , True]
Python Memory Management
IMMutable (int, float, str, tuple,set) vs Mutable (list, dict)
2592
memory loc. of list header
5576 2624 2656
1 2 3
9472
memory loc. of String header
6448 9664
p i
memory loc. of list header
5064 6064 6512 6448
300 503.2 String
5576 0288
List True
list_1[0]=500  list_1[0] is 500 at 1615190489840
list_1[3].append( [ "the" , "end“ ] )  list_1 is [500, 503.2, 'pi', [1, 2, 3, ['the', 'end']],
at 1615190605064
list_1[3].extend( [ "the" , "end“ ] )  list_1[3] is [1, 2, 3, ['the', 'end'], 'the', 'end']
at 1615103406448
500
9840 8424
List
5344
memory loc. of List header
8424 7888
the end
5344
the
7888
end
interning
We need more turtles
New memory location
Python Memory Management
Mutable vs immutable
Primitive data type single data value or
container of data
values
Mutable(allows
change with main
location unchanged)
immutable (must
change memory
location to change)
Access via square
brackets and index
or a key
Numbers (ints,
floats, complex)
one value immutable By name
String Container (Python
does not have a
character type)
Immutable [ position number ]
Lists Container Mutable ??? [ position number ]
Tuples Container Immutable ??? [ position number ]
Dictionaries Container Mutable Access using keys
Sets Container Immutable ???
russ.lavery@verizon.net 3/22/2021
8
A Deep Dive
into memory allocation
on the stack and on the heap
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
a is global with value Global stored at 2443812965680
At start of Hypot a= 5000 at 2441755614320
Base is= 3 at 140703449194960
Height is= 4 at 140703449194992
At start of DoSumming a= 2000 at 2441755614800
in Do_summing,x= 3 & is at 140703449194960 y= 4 & is at 140703449194992
At end of DoSumming a= 2000 at 2441755614800
in the return, call Do_Squaring twice and return values to hypot
At start of DoSquaring a= 1000 at 2441755614768
In Do_squaring Val_ is 3 & stored at 140703449194960
At end of DoSquaring a= 1000 at 2441755614768
Now, return a value from Do_Squaring to do summing
At start of DoSquaring a= 1000 at 2441755614768
In Do_squaring Val_ is 4 & stored at 140703449194992
At end of DoSquaring a= 1000 at 2441755614768
Now, return a value from Do_Squaring to do summing
We are back to Hypot, after control returns
At End of Hypot a= 5000 at 2441755614320
at end of Hypot, Base= 3 Height= 4 Hypot 5.0
a is global with value Global stored at 2443812965680
Python Memory Management
Lets see how this code 
runs on the stack and heap
Time for a deep dive
russ.lavery@verizon.net 3/22/2021
9
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Screen
Heap
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
“Global”
5680
a 5680
Heap
russ.lavery@verizon.net 3/22/2021
10
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
“Global”
5680
print
a
a is global with value
Global stored at
2443812965680
a 5680
Heap
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Hypot
Base  4960
Height  4992
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
11
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Hypot
Base  4960
Height  4992
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
a
Refcount=1
Type=int
MemLoc=4320 a  4320
Need space
on slide
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Hypot
Base  4960
Height  4992
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
At start of Hypot a= 5000 at
2441755614320
print
“At start…” a
a  4320
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
12
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Hypot
Base  4960
Height  4992
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
a  4320
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“Base is…” base
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Base is 3 at 4960
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
13
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“Height is…”Height
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Height is 4 at 4992
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
14
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
DoSumming
x 
y 
a 
Heap
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
4960
4992
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
15
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
DoSumming
x 
y 
a 
4960
4992
Global
Heap
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4800
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
“Global”
5680
a 5680
At start of DoSumming a =
2000 at 4800
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“At start of…” a
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
DoSumming
x 
y 
a 
4960
4992
4800
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
16
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Hypot
Base  4960
Height  4992
a  4320
Hypot 
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
DoSumming
x 
y 
a 
4960
4992
4800
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“in DoSumming…” x
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
in Do_summing x= 3 & is at
4960 y=4 at 4992
DoSumming
x 
y 
a 
4960
4992
4800
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
17
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“in the return…”
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
3
in the return, call
Do_Squaring twice and
return values to hypot
DoSumming
x 
y 
a 
4960
4992
4800
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
18
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Do_Squaring
Val_ 
a 
Heap
DoSumming
x 
y 
a 
4960
4992
4800
4960
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
3
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
19
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Do_Squaring
Val_ 
a 
Heap
DoSumming
x 
y 
a 
4960
4992
4800
4960
4768
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
3
“Global”
5680
a 5680
Note scope of a
Note scope of a
Note scope of a
Note scope of a
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“At start…” a
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
Do_Squaring
Val_ 
a 
DoSumming
x 
y 
a 
4960
4992
4800
4960
4768 = 1000
4768
Hypot
Base  4960
Height  4992
a  4320
Hypot 
At start of DoSquaring
a=",1000,"at ", 4786
3
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
20
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
Do_Squaring
Val_ 
a 
DoSumming
x 
y 
a 
4960
4992
4800
4960
4768 = 1000
4768
Hypot
Base  4960
Height  4992
a  4320
Hypot 
3
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“In DoSq…” Val_
Do_Squaring
Val_ 
a 
4960
4768
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
In Do_squaring Val_ is", 3,"&
stored at“ 4960
3
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
21
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Do_Squaring
Val_ 
a 
4960
4768
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
3
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“Now, return”
Do_Squaring
Val_ 
a 
4960
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
4768
Now, return a value from
Do_Squaring to do summing
3
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
22
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Do_Squaring
Val_ 
a 
4960
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
4768
3
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Val _**2
Do_Squaring
Val_ 
a 
4960
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
4768
9
3
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
23
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
9
Val_**2
&
Do_squaring(Val_):
Get deleted
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Do_Squaring
Val_ 
a 
4992
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
9
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
24
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Do_Squaring
Val_ 
a 
4992
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
4768
9
4 “Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“At start…” a
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
Do_Squaring
Val_ 
a 
4992
4768
9
4
At start of DoSquaring
a=",1000,"at ", 4768
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
25
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
Do_Squaring
Val_ 
a 
4992
4768
9
4 “Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“In Do…” Val_
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
Do_Squaring
Val_ 
a 
4992
4768
9
4
In Do_squaring Val_ is", 4,"&
stored at“ 4992
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
26
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
Do_Squaring
Val_ 
a 
4992
4768
9
4 “Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“Now, return…”
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
Do_Squaring
Val_ 
a 
4992
4768
Now, return a value from
Do_Squaring to do summing"
9
4 “Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
27
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
Do_Squaring
Val_ 
a 
4992
4768
9
4 “Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Val _**2
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
Do_Squaring
Val_ 
a 
4992
4768
9 16
4 “Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
28
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
DoSumming
x 
y 
a 
4960
4992
4800
9 16
“Global”
5680
a 5680 Val_**2
&
Do_squaring(Val_):
Get deleted
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
9 16
“Global”
5680
a 5680
DoSumming
is deleted
russ.lavery@verizon.net 3/22/2021
29
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
Sum of returned
values**.5 =5
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
Hypot
Base  4960
Height  4992
a  4320
Hypot  4802
4802= 5
9 16
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“We are back…”
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
We are back to Hypot, after
control returns
4802
4802= 5
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
30
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot  4802
4802= 5
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“At end of …” a
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
At End of Hypot a= 5000 at
4320
4802
4802= 5
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
31
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot  4802
4802= 5
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“at end of …”
Base
Height
Hypot
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot 
at end of Hypot, Base= 3
Height=4 Hypot 5
4802
4802= 5
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
32
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
Hypot
Base  4960
Height  4992
a  4320
Hypot  4802
4802= 5
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
4320 = 5000
4960 = 3
4992 = 4
4800 = 2000
4768 = 1000
4802= 5
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
33
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
print
“ a is global…” a
a is global with value Global
stored at 5680
“Global”
5680
a 5680
def Do_squaring(Val_):
a=1000
print("nAt start of DoSquaring a=",a,"at ",id(a) )
print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_))
print("Now, return a value from Do_Squaring to do summing")
return Val_**2
def DoSumming( x , y):
a=2000
print("nAt start of DoSumming a=",a,"at ",id(a) )
print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y))
print("in the return, call Do_Squaring twice and return values to hypot")
return Do_squaring(x) + Do_squaring(y)
def Hypot(Base, Height):
a=5000
print("nAt start of Hypot a=",a,"at ",id(a) )
print("Base is=",Base,"at ",id(Base) )
print("Height is=",Height,"at ",id(height) )
Hypot=(DoSumming(Base , Height) )**.5
print("nWe are back to Hypot, after control returns")
print("At End of Hypot a=",a,"at ",id(a) )
print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot)
a="Global"
print("a is global with value ",a, " stored at",id(a))
Hypot(3,4)
print("a is global with value ",a, " stored at",id(a))
Stack
Global
Heap
“Global”
5680
a 5680
russ.lavery@verizon.net 3/22/2021
34
Reference Counting and
Garbage Collection
Object management (think of the automatic process of managing objects)
needs to know three things about every object
1) The object Reference Count 2) The object Type 3) The object Value
a
Refcount=1
Type=int
MemLoc=4320
ref ="What?"
print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref )
Reuse1= ref ;
print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref ))
Contnr=["a list container", ref ]
print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref ))
def confused(x):
print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref ))
print("x is", x ,"at", id(x))
confused(ref )
print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref ))
del confused
print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref))
del Contnr
print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref))
del Reuse1
print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref))
del ref
print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref))
Ref. Ct, is 2 @ 2323390576496
Ref. Ct, is 3 @ 2323390576496
Ref. Ct, is 4 @ 2323390576496
Ref. Ct, is 6 @ 2323390576496
x is What? at 2323390576496
Ref. Ct, is 4 @ 2323390576496
Ref. Ct, is 4 @ 2323390576496
Ref. Ct, is 3 @ 2323390576496
Ref. Ct, is 2 @ 2323390576496
NameError: name 'ref' is not defined
Track refcount changes
Deleted a non-
running function
No change- Still 4
6 while function is running
Function ended
russ.lavery@verizon.net 3/22/2021
35
More about Functions and
Stack Frames
def Show_me( Location , A_contnr ):
print( Location, "nA_contnr=", A_contnr , "at“ , id(A_contnr) )
for i in range( 0 , len(A_contnr) ):
print( "at i=“, I ,"the elem is-->", A_contnr[i], "---at“ , id(A_contnr[i] ) )
print( Show_me( "Before any func“ , A_list ) )
Before any func
A_contnr= ['Where is the love', 'to be found?'] at 2021658868936
at i= 0 the elem is--> Where is the love ---at 2021658860560
at i= 1 the elem is--> to be found? ---at 2021654107760
A_list = [ "Where is the love“ , "to be found? “ ]
A utility function: to loop and show memory locations
Concrete Jungle
Catch a fire – Bob Marley and the Wailers 1973
A_list=[ "Where is the love", "to be found?“ ]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list ,"ooh" )
More about Functions and Stack Frames
Example 1 – Appending to a list from inside a function
Three appends
and
one insert
No return statement and no
assigning of the function results
to the original list
We will add several
"ooh“s
to the list
Scope Surprises
russ.lavery@verizon.net 3/22/2021
36
Stack
Global
A_list=["Where is the love",
"to be found?"]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
#this accesses the Global list
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list,"ooh")
More about Functions and Stack Frames
Heap
A_list 8936
8936 0560
7760
Where is the love
to be found?
7760
0560
A_list=["Where is the love",
"to be found?"]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
#this accesses the Global list
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list,"ooh")
Stack
Global
More about Functions and Stack Frames
Heap
A_list 8936
8936 0560
7760
Where is the love
to be found?
7760
0560
Append_in_Func
A_list  8936
A_list [0]  0560
A_list [1]  7660
russ.lavery@verizon.net 3/22/2021
37
A_list=["Where is the love",
"to be found?"]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
#this accesses the Global list
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list,"ooh")
Stack
Global
More about Functions and Stack Frames
Heap
A_list 8936
8936 0560
7760
Where is the love
to be found?
8016
7760
0560
8816
ooh
Append_in_Func
A_list  8936
A_list [0]  0560
A_list [1]  7660
A_list [2]  8016
Stack
Global
More about Functions and Stack Frames
Heap
A_list 8936
8936 0560
7760
Where is the love
to be found?
8016
7760
0560
8816
8016
ooh
Append_in_Func(A_list,"ooh")
Append_in_Func
A_list  8936
A_list [0]  0560
A_list [1]  7660
A_list [2]  8016
A_list [3]  8016
Exists
A_list=["Where is the love",
"to be found?"]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
#this accesses the Global list
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list,"ooh")
russ.lavery@verizon.net 3/22/2021
38
Stack
Global
More about Functions and Stack Frames
Heap
A_list 8936
8936 0560
7760
Where is the love
to be found?
8016
7760
0560
8816
8016
8016
ooh
Append_in_Func
A_list  8936
A_list [0]  0560
A_list [1]  7660
A_list [2]  8016
A_list [3]  8016
A_list [4]  8016
A_list=["Where is the love",
"to be found?"]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
#this accesses the Global list
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list,"ooh")
Stack
Global
More about Functions and Stack Frames
Heap
A_list 8936
Where is the love
to be found?
8016
7760
0560
8936 0560
7760
8816
8016
8016
ooh
Append_in_Func(A_list,"ooh")
Append_in_Func
A_list  8936
A_list [0]  0560
A_list [1]  7660
A_list [2]  8016
A_list [3]  8016
A_list [4]  8016
8936 0560
8016
7760
8016
8016
8016
Append_in_Func
A_list  8936
A_list [0]  0560
A_list [1]  8016
A_list [2]  7660
A_list [3]  8016
A_list [4]  8016
A_list [5]  8016
A_list=["Where is the love",
"to be found?"]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
#this accesses the Global list
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list,"ooh")
russ.lavery@verizon.net 3/22/2021
39
Stack
Global
More about Functions and Stack Frames
Heap
A_list 8936
Where is the love
to be found?
8016
7760
0560
8936 0560
8016
7760
8016
8016
8016
ooh
Append_in_Func(A_list,"ooh")
Appending, in a function, modifies the global
object
Ended
A_list=["Where is the love",
"to be found?"]
print(Show_me("Before func", A_list) )
def Append_in_Func(A_list, AnElement):
''' Append Accesses obj in stack'''
Show_me("nAt top of func" , A_list)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.append(AnElement)
A_list.insert(1,AnElement)
#this accesses the Global list
Show_me("At Bottom of func", A_list)
Append_in_Func(A_list,"ooh")
Stack heap is
erased.
A_list=[ "diǎn liàng“ , "wǒ“ , "shēngmìng de“ ]
Show_me("Before Function",A_list)
def Adding_W_Func(A_list, AnElement):
''' this = does not copy data '''
Show_me("n at TOP of the function",A_list)
A_list = A_list+ [AnElement , AnElement, AnElement, AnElement]
Show_me("n after the + ", A_list)
A_list.insert(1,AnElement)
Show_me("at Bottom of the function",A_list)
Adding_W_Func(A_list,"huǒ")
More about Functions and Stack Frames
Example 2 – using assign and + on a list from inside a function
Assigning &
appending
using + and
one insert
My little apple -- Chopstick Brothers
點亮我生命的火 火火火火火
the fire that lights up my life
diǎn liàng wǒ shēngmìng de huǒ huǒ huǒ huǒ huǒ huǒ
No return statement and no
assigning of the function
results to the original list
Scope Surprises
Python memory management_v2
Python memory management_v2
Python memory management_v2
Python memory management_v2
Python memory management_v2
Python memory management_v2
Python memory management_v2
Python memory management_v2
Python memory management_v2

More Related Content

What's hot

The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184Mahmoud Samir Fayed
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GParsPaul King
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview민태 김
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링Kwang Woo NAM
 
Pixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup SalzburgPixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup Salzburgwolframkriesing
 
Recentrer l'intelligence artificielle sur les connaissances
Recentrer l'intelligence artificielle sur les connaissancesRecentrer l'intelligence artificielle sur les connaissances
Recentrer l'intelligence artificielle sur les connaissancesMathieu d'Aquin
 
The Ring programming language version 1.3 book - Part 51 of 88
The Ring programming language version 1.3 book - Part 51 of 88The Ring programming language version 1.3 book - Part 51 of 88
The Ring programming language version 1.3 book - Part 51 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184Mahmoud Samir Fayed
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebChristian Baranowski
 
The Ring programming language version 1.5.3 book - Part 78 of 184
The Ring programming language version 1.5.3 book - Part 78 of 184The Ring programming language version 1.5.3 book - Part 78 of 184
The Ring programming language version 1.5.3 book - Part 78 of 184Mahmoud Samir Fayed
 
MongoDB Analytics
MongoDB AnalyticsMongoDB Analytics
MongoDB Analyticsdatablend
 
Vavr Java User Group Rheinland
Vavr Java User Group RheinlandVavr Java User Group Rheinland
Vavr Java User Group RheinlandDavid Schmitz
 
The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185Mahmoud Samir Fayed
 
Un monde où 1 ms vaut 100 M€ - Devoxx France 2015
Un monde où 1 ms vaut 100 M€ - Devoxx France 2015Un monde où 1 ms vaut 100 M€ - Devoxx France 2015
Un monde où 1 ms vaut 100 M€ - Devoxx France 2015ThierryAbalea
 
Java script objects 1
Java script objects 1Java script objects 1
Java script objects 1H K
 

What's hot (20)

The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview
 
Spock and Geb in Action
Spock and Geb in ActionSpock and Geb in Action
Spock and Geb in Action
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링집단지성 프로그래밍 08-가격모델링
집단지성 프로그래밍 08-가격모델링
 
Pixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup SalzburgPixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup Salzburg
 
Recentrer l'intelligence artificielle sur les connaissances
Recentrer l'intelligence artificielle sur les connaissancesRecentrer l'intelligence artificielle sur les connaissances
Recentrer l'intelligence artificielle sur les connaissances
 
The Ring programming language version 1.3 book - Part 51 of 88
The Ring programming language version 1.3 book - Part 51 of 88The Ring programming language version 1.3 book - Part 51 of 88
The Ring programming language version 1.3 book - Part 51 of 88
 
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
 
The Ring programming language version 1.5.3 book - Part 78 of 184
The Ring programming language version 1.5.3 book - Part 78 of 184The Ring programming language version 1.5.3 book - Part 78 of 184
The Ring programming language version 1.5.3 book - Part 78 of 184
 
MongoDB Analytics
MongoDB AnalyticsMongoDB Analytics
MongoDB Analytics
 
Vavr Java User Group Rheinland
Vavr Java User Group RheinlandVavr Java User Group Rheinland
Vavr Java User Group Rheinland
 
The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
 
Un monde où 1 ms vaut 100 M€ - Devoxx France 2015
Un monde où 1 ms vaut 100 M€ - Devoxx France 2015Un monde où 1 ms vaut 100 M€ - Devoxx France 2015
Un monde où 1 ms vaut 100 M€ - Devoxx France 2015
 
Good Code
Good CodeGood Code
Good Code
 
Java script objects 1
Java script objects 1Java script objects 1
Java script objects 1
 

Similar to Python memory management_v2

The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202Mahmoud Samir Fayed
 
RNN, LSTM and Seq-2-Seq Models
RNN, LSTM and Seq-2-Seq ModelsRNN, LSTM and Seq-2-Seq Models
RNN, LSTM and Seq-2-Seq ModelsEmory NLP
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
Python basic
Python basic Python basic
Python basic sewoo lee
 
한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남Eunjeong (Lucy) Park
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In RubyRoss Lawley
 
The (unknown) collections module
The (unknown) collections moduleThe (unknown) collections module
The (unknown) collections modulePablo Enfedaque
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」Ken'ichi Matsui
 
Clojure made really really simple
Clojure made really really simpleClojure made really really simple
Clojure made really really simpleJohn Stevenson
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseAlexander Galkin
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School ProgrammersSiva Arunachalam
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talkJohn Stevenson
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text ProcessingRodrigo Senra
 

Similar to Python memory management_v2 (20)

The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
RNN, LSTM and Seq-2-Seq Models
RNN, LSTM and Seq-2-Seq ModelsRNN, LSTM and Seq-2-Seq Models
RNN, LSTM and Seq-2-Seq Models
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Data types
Data typesData types
Data types
 
Python basic
Python basic Python basic
Python basic
 
한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남
 
Into Clojure
Into ClojureInto Clojure
Into Clojure
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
The (unknown) collections module
The (unknown) collections moduleThe (unknown) collections module
The (unknown) collections module
 
R intro 20140716-advance
R intro 20140716-advanceR intro 20140716-advance
R intro 20140716-advance
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
 
Clojure made really really simple
Clojure made really really simpleClojure made really really simple
Clojure made really really simple
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Procesos
ProcesosProcesos
Procesos
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
 

More from Jeffrey Clark

Jwt with flask slide deck - alan swenson
Jwt with flask   slide deck - alan swensonJwt with flask   slide deck - alan swenson
Jwt with flask slide deck - alan swensonJeffrey Clark
 
Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02Jeffrey Clark
 
Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02Jeffrey Clark
 
Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01Jeffrey Clark
 
Zpugdc deformpresentation-100709203803-phpapp01
Zpugdc deformpresentation-100709203803-phpapp01Zpugdc deformpresentation-100709203803-phpapp01
Zpugdc deformpresentation-100709203803-phpapp01Jeffrey Clark
 
Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Jeffrey Clark
 
Using Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig RhodesUsing Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig RhodesJeffrey Clark
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonJeffrey Clark
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonJeffrey Clark
 
Plone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno SchlichtingPlone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno SchlichtingJeffrey Clark
 
Real World Intranets - Joel Burton
Real World Intranets - Joel BurtonReal World Intranets - Joel Burton
Real World Intranets - Joel BurtonJeffrey Clark
 
State Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan RichterState Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan RichterJeffrey Clark
 
KSS Techniques - Joel Burton
KSS Techniques - Joel BurtonKSS Techniques - Joel Burton
KSS Techniques - Joel BurtonJeffrey Clark
 

More from Jeffrey Clark (20)

Python meetup
Python meetupPython meetup
Python meetup
 
Jwt with flask slide deck - alan swenson
Jwt with flask   slide deck - alan swensonJwt with flask   slide deck - alan swenson
Jwt with flask slide deck - alan swenson
 
Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02
 
Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02
 
Dc python meetup
Dc python meetupDc python meetup
Dc python meetup
 
Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01
 
Zpugdc deformpresentation-100709203803-phpapp01
Zpugdc deformpresentation-100709203803-phpapp01Zpugdc deformpresentation-100709203803-phpapp01
Zpugdc deformpresentation-100709203803-phpapp01
 
Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01
 
Tornado
TornadoTornado
Tornado
 
Science To Bfg
Science To BfgScience To Bfg
Science To Bfg
 
The PSF and You
The PSF and YouThe PSF and You
The PSF and You
 
Using Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig RhodesUsing Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig Rhodes
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike Robinson
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike Robinson
 
Plone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno SchlichtingPlone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno Schlichting
 
Real World Intranets - Joel Burton
Real World Intranets - Joel BurtonReal World Intranets - Joel Burton
Real World Intranets - Joel Burton
 
State Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan RichterState Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan Richter
 
KSS Techniques - Joel Burton
KSS Techniques - Joel BurtonKSS Techniques - Joel Burton
KSS Techniques - Joel Burton
 
Zenoss: Buildout
Zenoss: BuildoutZenoss: Buildout
Zenoss: Buildout
 
Opensourceweblion
OpensourceweblionOpensourceweblion
Opensourceweblion
 

Recently uploaded

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 

Recently uploaded (20)

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 

Python memory management_v2

  • 1. russ.lavery@verizon.net 3/22/2021 1 Python Memory Management Russ Lavery Advanced topic Focus will be: Vocabulary and Concepts Background for some talks about a very common error Knowing this lets you talk with IT You will Not be an expert or able to solve memory problems Memory Management in Python: Theresa Lee https://www.youtube.com/watch?v=3pXquKQf2qk Wesley Chun, "Python 103: Memory Model & Best Practices", PyBay2016 https://www.youtube.com/watch?v=SiXyyOA6RZg Kavya Joshi The Memory Chronicles A Tale of Two Pythons PyCon 2017 https://www.youtube.com/watch?v=d7qEzpnkWaY Pointers and dynamic memory - stack vs heap mycode_School https://www.youtube.com/watch?v=_8-ht2AKyH4 Rules of behaviour in a cartoon-like, visual, format Basic Pointers (interning of commonly used values)
  • 2. russ.lavery@verizon.net 3/22/2021 2 Python Memory Management This is for C-python and other pythons may be different Simple examples only Everything in Python is an object VarName=5 dir(VarName) Out[14]: ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', 'to_bytes'] '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', All variables/objects are stored in a complicated system of pointers to memory location. RAM has numbered memory locations, like lists Sections of RAM are reserved RAM Code: instruction Global Vars Heap Stack 100 200 300 400 500 600 700 800 900 1000 1100 1200 Often understood incompletely… Lets see some examples Python Memory Management Python has some tricks that even “catch” teachers Integers between -5 and 256 (might be expanded) are sent to pre-allocated memory locations in RAM NewVar1=VarName2 id(NewVar) x=333 id(x) 140714552500752 140714552500752 140714552500752 140714552500752 140714552500752 140714552500752 VarName2 NewVar 14…0752 14…0752 14…0752 5 140714552500752 VarName1 14…0752 Changes at every call 1513644174288 1513644174288 1513644174896 Changes at every call RAM VarName1=5 id(VarName1) VarName2=5 id(VarName2) id(5) id(5*1) id(10/2) id (100/20) y=x id(y) z=333 id(z) 333 74288 74896 333 All 5’s go to the same memory location Beware of rules/examples on Youtube that only show integer values between -5 and 256 We Want General Rules of Behavior!
  • 3. russ.lavery@verizon.net 3/22/2021 3 Python Memory Management Documents say that strings that are: are stored in the same memory location ¯_(ツ)_/¯ CV1 = "bed" id(CV1) CV2 = "bed" id(CV2) CV1 == CV2 id(CV1) == id(CV2) CV1 is CV2 1513661556720 1513661556720 True True True CV3='bed!' id(CV3) CV4='bed!' id(CV4) 1513661627696 151366171934 CV10 = "s" 1513545485040 1513550729840 1513545485040 1513546905456 less than a certain length…and are upper/lower letters, numbers and the underscore CV12='l' 1513546905456 1513545485232 1513545485232 1513545485232 1513545480688 s l e e p …5040 CV 11 …9840 …9840 …5456 …5232 …5232 …0688 Strings are “container objects” ! Blocks interning s e "sleep" l sleep l e sleep sleep sleep id(CV12) id('e') id(CV11[2]) id(CV11[3]) id(CV11[4]) sleep id(CV10) CV11 = "sleep" id(CV11) id(CV11[0]) id(CV11[1]) Start of container == compares value equality and ‘is’ checks if both variables refer to the same object. Python Memory Management Documents say that strings that are: CharVar1 = 'Z' 1513550636976 CharVar1==CharVar3 less than a certain length are upper/lower letters, numbers and the underscore 1513550636976 True CharVar4= 'z'.upper() 'Z' 1513661769200 After upper-casing Z character is in a different memory location CharVar1 , CharVar2 Z character in same memory locations CharVar1 , CharVar2 & CharVar3 Z character in same memory locations True True Also a Z id(CharVar1) == id(CharVar3) CharVar1 is CharVar3 id(CharVar1) CharVar2 = 'Z' id(CharVar2) CharVar3 = CharVar2 CharVar4 id(CharVar4) are stored in the same memory location ¯_(ツ)_/¯
  • 4. russ.lavery@verizon.net 3/22/2021 4 Mutable and Immutable object types Python Memory Management IMMutable (int, float, str, tuple,set) vs Mutable (list, dict) N1= 350 print("N1 is",N1 ,"at " ,id(N1 )) N2=N1 print("N2 is",N2 ,"at " ,id(N2 )) N3=350 print("N3 is",N3 ,"at " ,id(N3 )) N1 = N1+1 print("N1 is",N1 ,"at " ,id(N1 )) print("N2 is",N2 ,"at " ,id(N2 ))  N1 is 350 at 2208632141168  N2 is 350 at 2208632141168  N3 is 350 at 2208632140784  N1 is 351 at 2208632041200  N2 is 350 at 2208632141168 350 0784 N2 1168 N3 0784 350 1168 N1 1200 351 1200 N1 1168  No change Lookup table Value Storage Breaks (erases) connection of N1 to location 1168. Creates new N1 entries in lookup table and the value storage memory
  • 5. russ.lavery@verizon.net 3/22/2021 5 Python Memory Management IMMutable (int, float, str, tuple,set) vs Mutable (list, dict) Strng_1 ="Kpop" print( "Strng_1 is “ ,Strng_1 , "at " , id(Strng_1 ) ) print( "Strng_1[0] is“ ,Strng_1[0] , "at " , id(Strng_1[0] ) ) print( "Strng_1[1] is“ ,Strng_1[1] , "at " , id(Strng_1[1] ) ) print( "Strng_1[2] is“ ,Strng_1[2] , "at " , id(Strng_1[2] ) ) print( "Strng_1[3] is“ ,Strng_1[3] , "at " , id(Strng_1[3] ) ) Strng_1[1] = 'x' Strng_1 = Strng_1.lower() print( "Strng_1 is “ ,Strng_1 , "at " ,id(Strng_1 ) ) print( "Strng_1[0] is“ ,Strng_1[0] , "at " , id(Strng_1[0] ) ) print( "Strng_1[1] is“ ,Strng_1[1] , "at " , id(Strng_1[1] ) ) print( "Strng_1[2] is“ ,Strng_1[2] , "at " , id(Strng_1[2] ) ) print( "Strng_1[3] is“ ,Strng_1[3] , "at " , id(Strng_1[3] ) ) 7792 memory loc. of container header 6656 0240 5168 0240 K p o p  TypeError: 'str' object does not support item assignment 4304 memory loc. of container header 2608 0240 5168 0240 k p o p Cannot change a string IN IT’S CURRENT MEMORY LOCATION When you change/reassign a string, the container memory location changes But elements might be in the same memory location Lowercase and assign to original name Python Memory Management IMMutable (int, float, str, tuple,set) vs Mutable (list, dict) ''' Tuples are immutable ''' tup1 = 1,3,1 print( "tup1 is " , tup1 , "at“ , id(tup1 ) ) print( "tup1[0] is“ , tup1[0] , "at“ , id(tup1[0] ) ) print( "tup1[1] is“ , tup1[1] , "at“ , id(tup1[1] ) ) print( "tup1[2] is“ , tup1[2] , "at“ , id(tup1[2] ) ) ''‘Code below fails and so people say tuples are immutable ''' tup1[1] = 123  TypeError: 'tuple' object does not support item assignment '''however, mutable objects , in a tuple can be changed ''' 2592 memory loc. of tuple header 2664 2656 2592 1 3 1  tup1[2] is 1 at 140708655112592  tup1 is (1, 3, 1) at 1615190232664  tup1[0] is 1 at 140708655112592  tup1[1] is 3 at 140708655112656
  • 6. russ.lavery@verizon.net 3/22/2021 6 Python Memory Management IMMutable (int, float, str, tuple,set) vs Mutable (list, dict) tup2 =(1 , [ "A“ , "B“ , "C“ ] , 2) print( "tup2 is" ,tup2 , ‘at’ , id(tup2 )) print( "tup2[0] is“ ,tup2[0] , ‘at’ , id(tup2[0])) print( "tup2[1] is“ ,tup2[1] , ‘at’ , id(tup2[1])) print( "tup2[1] [0] is“ ,tup2[1][0] , ‘at’ , id(tup2[1] [0])) tup2[0] = 9  TypeError: 'tuple' object does not support item assignment Mutable objects , in a tuple, can be changed ''' 7728 memory loc. of tuple header 7032 6744 7760 1 List 2 7728 memory loc. of list header 6744 7312 7184 A B C We can not change a tuple element if the element is immutable… however, mutable elements/objects , in a tuple, can be changed A list Python Memory Management IMMutable (int, float, str, tuple,set) vs Mutable (list, dict) tup2[1] = ["Pesky","Wabbit"] tup2[1][0] = "Eah" tup2[1][1] = [ "Pesky“ , "Wabbit“ ] 7728 memory loc. of tuple header 7032 6744 7760 1 List 2 7728 memory loc. of list header 6744 7312 7184 A B C  TypeError: 'tuple' does not support item assignment tup2 =(1 , [ "A“ , "B“ , "C“ ] , 2) print( "tup2 is" ,tup2 , ‘at’ , id(tup2 )) print( "tup2[0] is“ ,tup2[0] , ‘at’ , id(tup2[0])) print( "tup2[1] is“ ,tup2[1] , ‘at’ , id(tup2[1])) print( "tup2[1] [0] is“ ,tup2[1][0] , ‘at’ , id(tup2[1] [0])) print( "tup2[1] [1] is“ ,tup2[1][1] , ‘at’ , id(tup2[1] [1])) print( "tup2[1] [2] is“ ,tup2[1][2] , ‘at’ , id(tup2[1] [2])) print( "tup2[2] is“ ,tup2[2] , ‘at’ , id(tup2[2])) 7728 memory loc. of tuple header 7032 6744 7760 1 List 2 7728 memory loc. of tuple header 6744 7312 7184 A B C "Eah" 7264 2120 List 1296 memory loc. of list header 2120 2192 Pesky Wabbit It is recursive turtles all the way down Mutable objects , in a tuple, can be changed ''' A list
  • 7. russ.lavery@verizon.net 3/22/2021 7 Lists are Mutable, however, immutable objs. in lists are immutable at same memory location''‘ list_1 = [ 300 , 503.2 , 'pi‘ , [ 1 , 2 , 3 ] , True] Python Memory Management IMMutable (int, float, str, tuple,set) vs Mutable (list, dict) 2592 memory loc. of list header 5576 2624 2656 1 2 3 9472 memory loc. of String header 6448 9664 p i memory loc. of list header 5064 6064 6512 6448 300 503.2 String 5576 0288 List True list_1[0]=500  list_1[0] is 500 at 1615190489840 list_1[3].append( [ "the" , "end“ ] )  list_1 is [500, 503.2, 'pi', [1, 2, 3, ['the', 'end']], at 1615190605064 list_1[3].extend( [ "the" , "end“ ] )  list_1[3] is [1, 2, 3, ['the', 'end'], 'the', 'end'] at 1615103406448 500 9840 8424 List 5344 memory loc. of List header 8424 7888 the end 5344 the 7888 end interning We need more turtles New memory location Python Memory Management Mutable vs immutable Primitive data type single data value or container of data values Mutable(allows change with main location unchanged) immutable (must change memory location to change) Access via square brackets and index or a key Numbers (ints, floats, complex) one value immutable By name String Container (Python does not have a character type) Immutable [ position number ] Lists Container Mutable ??? [ position number ] Tuples Container Immutable ??? [ position number ] Dictionaries Container Mutable Access using keys Sets Container Immutable ???
  • 8. russ.lavery@verizon.net 3/22/2021 8 A Deep Dive into memory allocation on the stack and on the heap a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) a is global with value Global stored at 2443812965680 At start of Hypot a= 5000 at 2441755614320 Base is= 3 at 140703449194960 Height is= 4 at 140703449194992 At start of DoSumming a= 2000 at 2441755614800 in Do_summing,x= 3 & is at 140703449194960 y= 4 & is at 140703449194992 At end of DoSumming a= 2000 at 2441755614800 in the return, call Do_Squaring twice and return values to hypot At start of DoSquaring a= 1000 at 2441755614768 In Do_squaring Val_ is 3 & stored at 140703449194960 At end of DoSquaring a= 1000 at 2441755614768 Now, return a value from Do_Squaring to do summing At start of DoSquaring a= 1000 at 2441755614768 In Do_squaring Val_ is 4 & stored at 140703449194992 At end of DoSquaring a= 1000 at 2441755614768 Now, return a value from Do_Squaring to do summing We are back to Hypot, after control returns At End of Hypot a= 5000 at 2441755614320 at end of Hypot, Base= 3 Height= 4 Hypot 5.0 a is global with value Global stored at 2443812965680 Python Memory Management Lets see how this code  runs on the stack and heap Time for a deep dive
  • 9. russ.lavery@verizon.net 3/22/2021 9 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Screen Heap def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global “Global” 5680 a 5680 Heap
  • 10. russ.lavery@verizon.net 3/22/2021 10 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global “Global” 5680 print a a is global with value Global stored at 2443812965680 a 5680 Heap def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Hypot Base  4960 Height  4992 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 “Global” 5680 a 5680
  • 11. russ.lavery@verizon.net 3/22/2021 11 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Hypot Base  4960 Height  4992 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 a Refcount=1 Type=int MemLoc=4320 a  4320 Need space on slide “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Hypot Base  4960 Height  4992 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 At start of Hypot a= 5000 at 2441755614320 print “At start…” a a  4320 “Global” 5680 a 5680
  • 12. russ.lavery@verizon.net 3/22/2021 12 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Hypot Base  4960 Height  4992 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 a  4320 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “Base is…” base Hypot Base  4960 Height  4992 a  4320 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Base is 3 at 4960 “Global” 5680 a 5680
  • 13. russ.lavery@verizon.net 3/22/2021 13 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Hypot Base  4960 Height  4992 a  4320 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “Height is…”Height Hypot Base  4960 Height  4992 a  4320 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Height is 4 at 4992 “Global” 5680 a 5680
  • 14. russ.lavery@verizon.net 3/22/2021 14 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Hypot Base  4960 Height  4992 a  4320 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global DoSumming x  y  a  Heap Hypot Base  4960 Height  4992 a  4320 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 4960 4992 “Global” 5680 a 5680
  • 15. russ.lavery@verizon.net 3/22/2021 15 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack DoSumming x  y  a  4960 4992 Global Heap Hypot Base  4960 Height  4992 a  4320 Hypot  4800 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 “Global” 5680 a 5680 At start of DoSumming a = 2000 at 4800 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “At start of…” a Hypot Base  4960 Height  4992 a  4320 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 DoSumming x  y  a  4960 4992 4800 “Global” 5680 a 5680
  • 16. russ.lavery@verizon.net 3/22/2021 16 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Hypot Base  4960 Height  4992 a  4320 Hypot  4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 DoSumming x  y  a  4960 4992 4800 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “in DoSumming…” x 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  in Do_summing x= 3 & is at 4960 y=4 at 4992 DoSumming x  y  a  4960 4992 4800 “Global” 5680 a 5680
  • 17. russ.lavery@verizon.net 3/22/2021 17 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “in the return…” 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  3 in the return, call Do_Squaring twice and return values to hypot DoSumming x  y  a  4960 4992 4800 “Global” 5680 a 5680
  • 18. russ.lavery@verizon.net 3/22/2021 18 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Do_Squaring Val_  a  Heap DoSumming x  y  a  4960 4992 4800 4960 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  3 “Global” 5680 a 5680
  • 19. russ.lavery@verizon.net 3/22/2021 19 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Do_Squaring Val_  a  Heap DoSumming x  y  a  4960 4992 4800 4960 4768 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  3 “Global” 5680 a 5680 Note scope of a Note scope of a Note scope of a Note scope of a def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “At start…” a 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 Do_Squaring Val_  a  DoSumming x  y  a  4960 4992 4800 4960 4768 = 1000 4768 Hypot Base  4960 Height  4992 a  4320 Hypot  At start of DoSquaring a=",1000,"at ", 4786 3 “Global” 5680 a 5680
  • 20. russ.lavery@verizon.net 3/22/2021 20 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 Do_Squaring Val_  a  DoSumming x  y  a  4960 4992 4800 4960 4768 = 1000 4768 Hypot Base  4960 Height  4992 a  4320 Hypot  3 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “In DoSq…” Val_ Do_Squaring Val_  a  4960 4768 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 In Do_squaring Val_ is", 3,"& stored at“ 4960 3 “Global” 5680 a 5680
  • 21. russ.lavery@verizon.net 3/22/2021 21 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Do_Squaring Val_  a  4960 4768 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 3 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “Now, return” Do_Squaring Val_  a  4960 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 4768 Now, return a value from Do_Squaring to do summing 3 “Global” 5680 a 5680
  • 22. russ.lavery@verizon.net 3/22/2021 22 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Do_Squaring Val_  a  4960 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 4768 3 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Val _**2 Do_Squaring Val_  a  4960 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 4768 9 3 “Global” 5680 a 5680
  • 23. russ.lavery@verizon.net 3/22/2021 23 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 9 Val_**2 & Do_squaring(Val_): Get deleted “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Do_Squaring Val_  a  4992 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 9 “Global” 5680 a 5680
  • 24. russ.lavery@verizon.net 3/22/2021 24 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Do_Squaring Val_  a  4992 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 4768 9 4 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “At start…” a 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 Do_Squaring Val_  a  4992 4768 9 4 At start of DoSquaring a=",1000,"at ", 4768 “Global” 5680 a 5680
  • 25. russ.lavery@verizon.net 3/22/2021 25 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 Do_Squaring Val_  a  4992 4768 9 4 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “In Do…” Val_ 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 Do_Squaring Val_  a  4992 4768 9 4 In Do_squaring Val_ is", 4,"& stored at“ 4992 “Global” 5680 a 5680
  • 26. russ.lavery@verizon.net 3/22/2021 26 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 Do_Squaring Val_  a  4992 4768 9 4 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “Now, return…” 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 Do_Squaring Val_  a  4992 4768 Now, return a value from Do_Squaring to do summing" 9 4 “Global” 5680 a 5680
  • 27. russ.lavery@verizon.net 3/22/2021 27 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 Do_Squaring Val_  a  4992 4768 9 4 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Val _**2 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 Do_Squaring Val_  a  4992 4768 9 16 4 “Global” 5680 a 5680
  • 28. russ.lavery@verizon.net 3/22/2021 28 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  DoSumming x  y  a  4960 4992 4800 9 16 “Global” 5680 a 5680 Val_**2 & Do_squaring(Val_): Get deleted def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  9 16 “Global” 5680 a 5680 DoSumming is deleted
  • 29. russ.lavery@verizon.net 3/22/2021 29 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap Sum of returned values**.5 =5 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 Hypot Base  4960 Height  4992 a  4320 Hypot  4802 4802= 5 9 16 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “We are back…” 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  We are back to Hypot, after control returns 4802 4802= 5 “Global” 5680 a 5680
  • 30. russ.lavery@verizon.net 3/22/2021 30 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  4802 4802= 5 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “At end of …” a 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  At End of Hypot a= 5000 at 4320 4802 4802= 5 “Global” 5680 a 5680
  • 31. russ.lavery@verizon.net 3/22/2021 31 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  4802 4802= 5 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “at end of …” Base Height Hypot 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  at end of Hypot, Base= 3 Height=4 Hypot 5 4802 4802= 5 “Global” 5680 a 5680
  • 32. russ.lavery@verizon.net 3/22/2021 32 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 Hypot Base  4960 Height  4992 a  4320 Hypot  4802 4802= 5 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap 4320 = 5000 4960 = 3 4992 = 4 4800 = 2000 4768 = 1000 4802= 5 “Global” 5680 a 5680
  • 33. russ.lavery@verizon.net 3/22/2021 33 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap print “ a is global…” a a is global with value Global stored at 5680 “Global” 5680 a 5680 def Do_squaring(Val_): a=1000 print("nAt start of DoSquaring a=",a,"at ",id(a) ) print("In Do_squaring Val_ is", Val_,"& stored at",id(Val_)) print("Now, return a value from Do_Squaring to do summing") return Val_**2 def DoSumming( x , y): a=2000 print("nAt start of DoSumming a=",a,"at ",id(a) ) print("in Do_summing,x=", x, "& is at",id(x),"y=",y,"& is at",id(y)) print("in the return, call Do_Squaring twice and return values to hypot") return Do_squaring(x) + Do_squaring(y) def Hypot(Base, Height): a=5000 print("nAt start of Hypot a=",a,"at ",id(a) ) print("Base is=",Base,"at ",id(Base) ) print("Height is=",Height,"at ",id(height) ) Hypot=(DoSumming(Base , Height) )**.5 print("nWe are back to Hypot, after control returns") print("At End of Hypot a=",a,"at ",id(a) ) print("at end of Hypot, Base=",Base,"Height=", Height,"Hypot", Hypot) a="Global" print("a is global with value ",a, " stored at",id(a)) Hypot(3,4) print("a is global with value ",a, " stored at",id(a)) Stack Global Heap “Global” 5680 a 5680
  • 34. russ.lavery@verizon.net 3/22/2021 34 Reference Counting and Garbage Collection Object management (think of the automatic process of managing objects) needs to know three things about every object 1) The object Reference Count 2) The object Type 3) The object Value a Refcount=1 Type=int MemLoc=4320 ref ="What?" print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref ) Reuse1= ref ; print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref )) Contnr=["a list container", ref ] print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref )) def confused(x): print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref )) print("x is", x ,"at", id(x)) confused(ref ) print("Ref. Ct, is",sys.getrefcount(ref ),"@",id(ref )) del confused print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref)) del Contnr print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref)) del Reuse1 print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref)) del ref print("Ref. Ct, is",sys.getrefcount(ref),"@",id(ref)) Ref. Ct, is 2 @ 2323390576496 Ref. Ct, is 3 @ 2323390576496 Ref. Ct, is 4 @ 2323390576496 Ref. Ct, is 6 @ 2323390576496 x is What? at 2323390576496 Ref. Ct, is 4 @ 2323390576496 Ref. Ct, is 4 @ 2323390576496 Ref. Ct, is 3 @ 2323390576496 Ref. Ct, is 2 @ 2323390576496 NameError: name 'ref' is not defined Track refcount changes Deleted a non- running function No change- Still 4 6 while function is running Function ended
  • 35. russ.lavery@verizon.net 3/22/2021 35 More about Functions and Stack Frames def Show_me( Location , A_contnr ): print( Location, "nA_contnr=", A_contnr , "at“ , id(A_contnr) ) for i in range( 0 , len(A_contnr) ): print( "at i=“, I ,"the elem is-->", A_contnr[i], "---at“ , id(A_contnr[i] ) ) print( Show_me( "Before any func“ , A_list ) ) Before any func A_contnr= ['Where is the love', 'to be found?'] at 2021658868936 at i= 0 the elem is--> Where is the love ---at 2021658860560 at i= 1 the elem is--> to be found? ---at 2021654107760 A_list = [ "Where is the love“ , "to be found? “ ] A utility function: to loop and show memory locations Concrete Jungle Catch a fire – Bob Marley and the Wailers 1973 A_list=[ "Where is the love", "to be found?“ ] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) Show_me("At Bottom of func", A_list) Append_in_Func(A_list ,"ooh" ) More about Functions and Stack Frames Example 1 – Appending to a list from inside a function Three appends and one insert No return statement and no assigning of the function results to the original list We will add several "ooh“s to the list Scope Surprises
  • 36. russ.lavery@verizon.net 3/22/2021 36 Stack Global A_list=["Where is the love", "to be found?"] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) #this accesses the Global list Show_me("At Bottom of func", A_list) Append_in_Func(A_list,"ooh") More about Functions and Stack Frames Heap A_list 8936 8936 0560 7760 Where is the love to be found? 7760 0560 A_list=["Where is the love", "to be found?"] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) #this accesses the Global list Show_me("At Bottom of func", A_list) Append_in_Func(A_list,"ooh") Stack Global More about Functions and Stack Frames Heap A_list 8936 8936 0560 7760 Where is the love to be found? 7760 0560 Append_in_Func A_list  8936 A_list [0]  0560 A_list [1]  7660
  • 37. russ.lavery@verizon.net 3/22/2021 37 A_list=["Where is the love", "to be found?"] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) #this accesses the Global list Show_me("At Bottom of func", A_list) Append_in_Func(A_list,"ooh") Stack Global More about Functions and Stack Frames Heap A_list 8936 8936 0560 7760 Where is the love to be found? 8016 7760 0560 8816 ooh Append_in_Func A_list  8936 A_list [0]  0560 A_list [1]  7660 A_list [2]  8016 Stack Global More about Functions and Stack Frames Heap A_list 8936 8936 0560 7760 Where is the love to be found? 8016 7760 0560 8816 8016 ooh Append_in_Func(A_list,"ooh") Append_in_Func A_list  8936 A_list [0]  0560 A_list [1]  7660 A_list [2]  8016 A_list [3]  8016 Exists A_list=["Where is the love", "to be found?"] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) #this accesses the Global list Show_me("At Bottom of func", A_list) Append_in_Func(A_list,"ooh")
  • 38. russ.lavery@verizon.net 3/22/2021 38 Stack Global More about Functions and Stack Frames Heap A_list 8936 8936 0560 7760 Where is the love to be found? 8016 7760 0560 8816 8016 8016 ooh Append_in_Func A_list  8936 A_list [0]  0560 A_list [1]  7660 A_list [2]  8016 A_list [3]  8016 A_list [4]  8016 A_list=["Where is the love", "to be found?"] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) #this accesses the Global list Show_me("At Bottom of func", A_list) Append_in_Func(A_list,"ooh") Stack Global More about Functions and Stack Frames Heap A_list 8936 Where is the love to be found? 8016 7760 0560 8936 0560 7760 8816 8016 8016 ooh Append_in_Func(A_list,"ooh") Append_in_Func A_list  8936 A_list [0]  0560 A_list [1]  7660 A_list [2]  8016 A_list [3]  8016 A_list [4]  8016 8936 0560 8016 7760 8016 8016 8016 Append_in_Func A_list  8936 A_list [0]  0560 A_list [1]  8016 A_list [2]  7660 A_list [3]  8016 A_list [4]  8016 A_list [5]  8016 A_list=["Where is the love", "to be found?"] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) #this accesses the Global list Show_me("At Bottom of func", A_list) Append_in_Func(A_list,"ooh")
  • 39. russ.lavery@verizon.net 3/22/2021 39 Stack Global More about Functions and Stack Frames Heap A_list 8936 Where is the love to be found? 8016 7760 0560 8936 0560 8016 7760 8016 8016 8016 ooh Append_in_Func(A_list,"ooh") Appending, in a function, modifies the global object Ended A_list=["Where is the love", "to be found?"] print(Show_me("Before func", A_list) ) def Append_in_Func(A_list, AnElement): ''' Append Accesses obj in stack''' Show_me("nAt top of func" , A_list) A_list.append(AnElement) A_list.append(AnElement) A_list.append(AnElement) A_list.insert(1,AnElement) #this accesses the Global list Show_me("At Bottom of func", A_list) Append_in_Func(A_list,"ooh") Stack heap is erased. A_list=[ "diǎn liàng“ , "wǒ“ , "shēngmìng de“ ] Show_me("Before Function",A_list) def Adding_W_Func(A_list, AnElement): ''' this = does not copy data ''' Show_me("n at TOP of the function",A_list) A_list = A_list+ [AnElement , AnElement, AnElement, AnElement] Show_me("n after the + ", A_list) A_list.insert(1,AnElement) Show_me("at Bottom of the function",A_list) Adding_W_Func(A_list,"huǒ") More about Functions and Stack Frames Example 2 – using assign and + on a list from inside a function Assigning & appending using + and one insert My little apple -- Chopstick Brothers 點亮我生命的火 火火火火火 the fire that lights up my life diǎn liàng wǒ shēngmìng de huǒ huǒ huǒ huǒ huǒ huǒ No return statement and no assigning of the function results to the original list Scope Surprises