#!/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 1: String - an immutable type # There's nothing we can do to change the contents of the string. # A tring parameter is passed by value, assigning a new string # to it within the function has no effect. The string inside # the function is a copy of the original string. def try_to_change_string_reference(the_string): print 'got', the_string the_string = 'In a kingdom by the sea' print 'set to', the_string outer_string = 'It was many and many a year ago' print 'before, outer_string =', outer_string try_to_change_string_reference(outer_string) print 'after, outer_string =', outer_string