title: Why is an in-place integer operation like a *= b slower than a = a * b?
body: <p>I know integers are immutable so the computed values do not modify the original integers. Therefore the in-place operations should do the same as the simple operations, 1. compute the value and 2. reassign the value back to the variable. But why are the in-place operations slower than the simple ones?</p>
  <pre><code>import timeit
  print(&quot;a = a + 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a = a + 1&quot;, setup=&quot;a = 0&quot;))
  print(&quot;a += 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a += 1&quot;, setup=&quot;a = 0&quot;))
  
  print(&quot;a = a - 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a = a - 1&quot;, setup=&quot;a = 0&quot;))
  print(&quot;a -= 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a -= 1&quot;, setup=&quot;a = 0&quot;))
  
  print(&quot;a = a * 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a = a * 1&quot;, setup=&quot;a = 1&quot;))
  print(&quot;a *= 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a *= 1&quot;, setup=&quot;a = 1&quot;))
  
  print(&quot;a = a // 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a = a // 1&quot;, setup=&quot;a = 1&quot;))
  print(&quot;a //= 1: &quot;, end=&quot;&quot;)
  print(timeit.timeit(&quot;for i in range(100): a //= 1&quot;, setup=&quot;a = 1&quot;))
  </code></pre>
  <p>Output:</p>
  <pre><code>a = a + 1: 2.922127154
  a += 1: 2.9701245480000003
  a = a - 1: 2.9568866799999993
  a -= 1: 3.1065419050000003
  a = a * 1: 2.2483990140000003
  a *= 1: 2.703524648
  a = a // 1: 2.534561783000001
  a //= 1: 2.6582312889999997
  </code></pre>
  <p>All the in-place operations are slower than the simple ones. Addition has the smallest difference while multiplication has the greatest.</p>