title: Python equivalent of php base64_encode
body: <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
  
  $string = base64_encode(sha1( 'ABCD' , true ) );
  echo sha1('ABCD');
  echo $string;
  ?&gt;
  </code></pre>
  
  <p>Output:</p>
  
  <p>fb2f85c88567f3c8ce9b799c7c54642d0c7b41f6</p>
  
  <p>+y+FyIVn88jOm3mcfFRkLQx7QfY=</p>
  
  <p><strong>Python</strong></p>
  
  <pre><code>import base64
  import hashlib
  
  s = hashlib.sha1()
  s.update('ABCD')
  myhash = s.hexdigest()
  print myhash
  print base64.encodestring(myhash)
  </code></pre>
  
  <p>Output:</p>
  
  <p>'fb2f85c88567f3c8ce9b799c7c54642d0c7b41f6'
  ZmIyZjg1Yzg4NTY3ZjNjOGNlOWI3OTljN2M1NDY0MmQwYzdiNDFmNg==</p>
  
  <p>Both the PHP and Python SHA1 works fine, but the <code>base64.encodestring()</code> in python returns a different value compared to <code>base64_encode()</code> in PHP.</p>
  
  <p>What is the equivalent method for PHP <code>base64_encode</code> in Python?</p>