#!/usr/bin/env python """ Parameters in Python are passed by value. We need to have in mind the following: 1- The parameter passed in is actually a reference to a variable (but the reference is passed by value) 2- Some data types are mutable, but others aren't """ # Example 2: List - a mutable type # A list parameter is passed by value, assigning # a new list to it had no effect that the code # outside the method could see. # The list inisde the function is a copy of the # original list reference, and we have a list pointing # to a new list, but there is no way to change where # the original list pointed. def try_to_change_list_reference(the_list): print 'got', the_list the_list = ['and', 'we', 'can', 'not', 'lie'] print 'set to', the_list outer_list = ['we', 'like', 'proper', 'English'] print 'before, outer_list =', outer_list try_to_change_list_reference(outer_list) print 'after, outer_list =', outer_list