Passing lists and individual list elements to functions. : parameter « Function « Python Tutorial






def modifyList( aList ):
   for i in range( len( aList ) ):
      aList[ i ] *= 2

def modifyElement( element ):
   element *= 2

aList = [ 1, 2, 3, 4, 5 ]

print "Effects of passing entire list:"
print "The values of the original list are:"

for item in aList:
   print item,

modifyList( aList )

for item in aList:
   print item,

print "aList[ 3 ] before modifyElement:", aList[ 3 ]
modifyElement( aList[ 3 ] )
print "aList[ 3 ] after modifyElement:", aList[ 3 ]

print "aList[ 2:4 ] before modifyList:", aList[ 2:4 ]
modifyList( aList[ 2:4 ] )
print "aList[ 2:4 ] after modifyList:", aList[ 2:4 ]








10.2.parameter
10.2.1.The semantics of argument passing
10.2.2.Pass functions to other functions as arguments
10.2.3.Passing Functions as parameter
10.2.4.Passing and Calling (Built-in) Functions
10.2.5.Positional Arguments
10.2.6.Passing lists and individual list elements to functions.
10.2.7.Simulating Output Parameters
10.2.8.Unpacking arguments