title: How do I go about simulating the equivalent of pass-by-reference in Python?
body: <p>What I essentially need is a mutable integer which can accomplish the equivalent of the below without having to resort to using single element lists.</p>
  
  <p>Below is a <strong>contrived code sample</strong> which is representative of the essence of my actual use case <strong>[1]</strong></p>
  
  <pre><code>&gt;&gt;&gt; a = [5]  
  &gt;&gt;&gt; b = [77]  
  &gt;&gt;&gt; def swap(num1, num2):  
  ...     temp = num1[0]  
  ...     num1[0] = num2[0]  
  ...     num2[0] = temp  
  &gt;&gt;&gt; swap(a, b)  
  &gt;&gt;&gt; a  
  [77]  
  &gt;&gt;&gt; b  
  [5]  
  </code></pre>
  
  <p><strong>[1]</strong> My actual use case is closer to this -> 
  <a href="https://stackoverflow.com/questions/5374354/returning-a-value-after-calling-a-function-with-a-button-in-tkinter">Returning a value after calling a function with a button in Tkinter</a><br>
  I need to return a value from a callback function associated with a Tkinter widget, and I would like to avoid globals.</p>