chr() equivalent returning a bytes object, in py3k April 27, 2023 by Tarik Try the following: b = bytes([x]) For example: >>> bytes([255]) b'\xff'