View
2
Download
0
Category
Preview:
Citation preview
ARGUMENT NUANCES
• In Python function invocations, copies of the values of arguments are used to initialize the parameters. This style of parameter passing is known as pass by value.
• Because copies are used, the values of the arguments cannot be modified within the function being invoked.
SETUP
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
f()
rmbr
x
y
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
f()
rmbr
x
y
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
f()
rmbr
x
y
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
f()
rmbr
x
y
f()
rmbr
x
y
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
f()
rmbr
x
y
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
f()
rmbr
x
y
Program cautionary.py
import tale
city1 = 'London'
city2 = 'Paris’
tale.f( city1, city2 )
print( city1, city2 )
PYTHON FILES
Module tale.py
def f( x, y ) :
rmbr = x
x = y
y = rmbr
main
city1
city2
’London'
'Paris'
f()
rmbr
x
y
main
city1
city2
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def zero( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
out()
x
i
n
out()
x
i
n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
out()
x
i
n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
out()
x
i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
out()
x
i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
out()
x
0 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
out()
x
0 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 3 1 4
out()
x
0 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 1 4
out()
x
0 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 1 4
out()
x
1 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 1 4
out()
x
1 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 1 4
out()
x
1 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 4
out()
x
1 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 4
out()
x
2 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 4
out()
x
2 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 4
out()
x
2 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 0
out()
x
2 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 0
out()
x
2 i
3 n
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 0
main
nbrs
Program wipe.py
import zero
nbrs = [ 3, 1, 4 ]
zero.out( nbrs )
print( nbrs )
PYTHON FILES
Module zero.py
def out( x) :
n = len( x )
for i in range( 0, n ) :
x[ i ] = 0
main
nbrs 0 0 0
main
nbrs
Recommended