擅长:python、mysql、java
<p>自从Python 3.5之后,这一点终于不再尴尬了:</p>
<pre><code>>>> b'\xde\xad\xbe\xef'.hex()
'deadbeef'
</code></pre>
<p>和背面:</p>
<pre><code>>>> bytes.fromhex('deadbeef')
b'\xde\xad\xbe\xef'
</code></pre>
<p>也适用于可变的<code>bytearray</code>类型。</p>
<p>引用:<a href="https://docs.python.org/3/library/stdtypes.html#bytes.hex" rel="noreferrer">https://docs.python.org/3/library/stdtypes.html#bytes.hex</a></p>