title: Storing an integer less than 256 within a byte of memory in Python
body: <p>I have a huge array (of arrays) of integers in the range 0-255. Since I know the range of the integers, hence I want to optimize the space occupied by them by storing each integer within a single byte.</p>
  
  <p>In C++, I would simply use <code>char</code> to store the integers, but I am not able to find a way out in Python.</p>
  
  <pre><code>&gt;&gt;&gt; a = 10
  &gt;&gt;&gt; sys.getsizeof(a)
  24
  &gt;&gt;&gt; b = chr(a)
  &gt;&gt;&gt; sys.getsizeof(b)
  38
  &gt;&gt;&gt; c = bytearray(1)
  &gt;&gt;&gt; c[0] = b
  &gt;&gt;&gt; c[0]
  10
  &gt;&gt;&gt; sys.getsizeof(c[0])
  24
  &gt;&gt;&gt; c
  bytearray(b'\n')
  &gt;&gt;&gt; sys.getsizeof(c)
  50
  </code></pre>
  
  <p>I have searched for data types available in Python, but I am not able to get any data type which can give me <code>sys.getsizeof()</code> equal to 1.
  I want to know whether there exists a spatially optimal way of storing such integers.</p>