How do I change where a variable is pointing to within a function?
<p>I have a python function that takes an object and either modifies it or replaces it.</p>

<pre><code>def maybe_replace_corgi(corgi):
  # If corgi is cute enough, modify it to keep it.
  if corgi.cuteness &gt; threshold:
    corgi.will_keep = True
  else:
    # Corgi not cute enough! Instantiate new corgi.
    corgi = Corgi(name="Woofus")
</code></pre>

<p>I know that objects are passed into python functions by reference. But what if I want to replace an object within a function entirely? As I want to do in my else statement? How do I make all references to the corgi object in my program point to this new corgi object?</p>
