title: Pointers in Python?
body: <p>I know Python doesn't have pointers, but is there a way to have this yield <code>2</code> instead</p>
  
  <pre><code>&gt;&gt;&gt; a = 1
  &gt;&gt;&gt; b = a # modify this line somehow so that b "points to" a
  &gt;&gt;&gt; a = 2
  &gt;&gt;&gt; b
  1
  </code></pre>
  
  <p>?</p>
  
  <hr>
  
  <p>Here's an example: I want <code>form.data['field']</code> and <code>form.field.value</code> to always have the same value. It's not completely necessary, but I think it would be nice.</p>
  
  <hr>
  
  <p>In PHP, for example, I can do this:</p>
  
  <pre><code>&lt;?php
  
  class Form {
      public $data = [];
      public $fields;
  
      function __construct($fields) {
          $this-&gt;fields = $fields;
          foreach($this-&gt;fields as &amp;$field) {
              $this-&gt;data[$field['id']] = &amp;$field['value'];
          }
      }
  }
  
  $f = new Form([
      [
          'id' =&gt; 'fname',
          'value' =&gt; 'George'
      ],
      [
          'id' =&gt; 'lname',
          'value' =&gt; 'Lucas'
      ]
  ]);
  
  echo $f-&gt;data['fname'], $f-&gt;fields[0]['value']; # George George
  $f-&gt;data['fname'] = 'Ralph';
  echo $f-&gt;data['fname'], $f-&gt;fields[0]['value']; # Ralph Ralph
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>GeorgeGeorgeRalphRalph
  </code></pre>
  
  <p><a href="https://ideone.com/W1rZML" rel="noreferrer">ideone</a></p>
  
  <hr>
  
  <p>Or like this in C++ (I think this is right, but my C++ is rusty):</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      int* a;
      int* b = a;
      *a = 1;
      cout &lt;&lt; *a &lt;&lt; endl &lt;&lt; *b &lt;&lt; endl; # 1 1
  
      return 0;
  }
  </code></pre>