It is in Python 2, but not in Python 3, where str.encode() and bytes.decode() have been restricted to only convert between strings and bytes.<p><pre><code>    &gt;&gt;&gt; &quot;foo&quot;.encode(&#x27;zlib&#x27;)
    LookupError: &#x27;zlib&#x27; is not a text encoding; use codecs.encode() to handle arbitrary codecs</code></pre>