Parameter Passing and Return Values

Parameters are passed by reference

  • This has certain implications for lists, dictionaries, and similar types
     def foo(x):
         x[2] = 10
     
     a = [1,2,3,4,5]
     foo(a)
     print a             # Outputs '[1, 2, 10, 4, 5]'

Return values

  • Values are returned as a tuple of results.
     def foo():
         ...
         return (x,y,z)
     
     d = foo()          # Gets a tuple with three values
     (a,b,c) = foo()    # Assigns values to a, b, and c.
     a,b,c = foo()      # Same thing 
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 83
July 17, 2000, beazley@cs.uchicago.edu
>>>