Am Fri, 2 Jul 2021 18:19:39 +0200 schrieb Marek Marczykowski-Górecki : > Why bytes()? Encode does already return bytes type. You are right, this works as well: i = 123 b = ("str/%x" % (i, )).encode('utf-8') Any preference regarding the "encoding"? I picked UTF8, but 'ascii' might be more correct in this context. In practice it may not matter. Olaf