<div><h3id="encode-1">Encode</h3><pre><codeclass="python language-python hljs"><bytes> = bytes(<coll_of_ints>) <spanclass="hljs-comment"># Ints must be in range from 0 to 255.</span>
<bytes> = bytes(<str>, <spanclass="hljs-string">'utf-8'</span>) <spanclass="hljs-comment"># Encodes string. Also <str>.encode('utf-8').</span>
<bytes> = bytes(<str>, <spanclass="hljs-string">'utf-8'</span>) <spanclass="hljs-comment"># Encodes the string. Also <str>.encode().</span>
<bytes> = bytes.fromhex(<spanclass="hljs-string">'<hex>'</span>) <spanclass="hljs-comment"># Hex pairs can be separated by whitespaces.</span>
<div><h3id="decode-1">Decode</h3><pre><codeclass="python language-python hljs"><list> = list(<bytes>) <spanclass="hljs-comment"># Returns ints in range from 0 to 255.</span>
<str> = str(<bytes>, <spanclass="hljs-string">'utf-8'</span>) <spanclass="hljs-comment"># Decodes bytes. Also <bytes>.decode('utf-8').</span>
<str> = str(<bytes>, <spanclass="hljs-string">'utf-8'</span>) <spanclass="hljs-comment"># Returns a string. Also <bytes>.decode().</span>