title: Why does [x] * n use less memory then [x for _ in range(n)] in Python?
body: <p>I was comparing speed, and memory usage of different data structures in Python3.8.</p>
  <p>When comparing 2 methods for making lists I found they used up a different amount of memory.</p>
  <pre><code>import sys
  
  x = 0
  n = 100
  method1 = [x for _ in range(n)]
  method2 = [x] * n
  
  print(sys.getsizeof(method1))
  print(sys.getsizeof(method2))
  
  # Output:
  904
  856
  </code></pre>
  <p>I didn't understand why this was the case so I tried the following things (using 'methody' as an example):</p>
  <ul>
  <li>printing the lists. <code>print(methody)</code></li>
  <li>printing their lengths.<code>print(len(methody))</code></li>
  <li>replacing x with another value. <code>x = 30</code> <code>x = 'a'</code></li>
  <li>replacing n with another value. <code>n = 5</code> <code>n = 1000</code></li>
  <li>replacing certain values. <code>methody[2] = 'a'</code> -&gt; <code>print(methody)</code></li>
  </ul>
  <p>They both gave the same results each time so I'm still confused.</p>
  <p>Can someone explain this memory difference?</p>