title: How to compare two byte arrays in Python
body: <p>I am trying to compare two byte arrays in Python.</p>
  <p>This is my code</p>
  <pre><code>print(&quot;new_digest: &quot;, new_digest)
  print(&quot;digest: &quot;, digest)
  if digest == new_digest:
      return True
  else:
      return False
  </code></pre>
  <p>and this is the output:</p>
  <pre><code>new_digest:  b&quot;&lt;\xc3\xb8\xa9'3\x81\xa2\xfb\xf7\xbfCm\xa8\xd6O\xd0\x03\xdd\xfadW\xfd,\xed\x03\\m\x87\xf8*&quot;
  
  digest:  b&quot;&lt;\xc3\xb8\xa9'3\x81\xa2\xfb\xf7\xbfCm\xa8\xd6O\xd0\x03\xdd\xfadW\xfd,\xed\x03\\m\x87\xf8*&quot;
  </code></pre>
  <p>It is clear that they are equal but the function is returning false. Why is this?</p>
  <p>The byte streams are generated using</p>
  <pre><code>from cryptography.hazmat.primitives import hashes
  digest = hashes.Hash(hashes.SHA256())
  digest.update(message)
  digest = digest.finalize()
  </code></pre>