擅长:python、mysql、java
<p>只需使用空字节字符串<code>b''</code>。</p>
<p>但是,重复地连接到字符串需要多次复制该字符串。可变的<a href="http://docs.python.org/3/library/stdtypes.html#typebytearray">^{<cd2>}</a>可能更快:</p>
<pre><code>msg = bytearray() # New empty byte array
# Append data to the array
msg.extend(b"blah")
msg.extend(b"foo")
</code></pre>
<p>要将字节数组解码为字符串,请使用<code>msg.decode(encoding='utf-8')</code>。</p>