title: Python Convert ASCII characters to bytes
body: <p>I want to convert some input ASCII characters into bytes. Such as from 'a' to 01100001.<br>
  I have read answers like <a href="https://stackoverflow.com/questions/4523551/python-ascii-to-binary">this</a>. But sometimes it gives out 0b10000110 like 9 digits values. I am not sure if that's an error or that's the way it supposes to work. 
   I have made something like this:</p>
  
  <pre><code>text = list(input("text: "))
  
  for character in text:
      if character == ' ':
          byt = '00000000'
      else:
          byt = bin(ord(character))
      byt = byt.replace('b', '') #delete the 'b' in the output
      if len(byt) != 8:
          byt = '0' + byt
      print(byt)
  </code></pre>
  
  <p>It worked pretty well with normal characters. But when I entered weird characters like: 'B<br>
  It outputs very strangely:</p>
  
  <pre><code>001110
  00100111
  0010000000
  01000010
  </code></pre>
  
  <p>I am not very experienced with Python, so I don't know if there is a way that you can write a function or other methods to do this.<br>
  I am using Python 3.6<br>
  Many thanks</p>