Search code examples
pythonpython-3.xcompatibilitybackwards-compatibility

Since when does the bytes() function exist in Python?


Since which version does the bytes() function exist in Python? I'm writing some code that has to be compatible with as much versions of python as possible, so this kind of information is very important to me. Is there a good source to find the answer to such questions easily?


Solution

  • PEP 3112 added support for bytes literal in Python3. Python 3 adopted Unicode as the language’s fundamental string type and denoted 8-bit literals either as b'string' or using a bytes constructor.

    For future compatiblity, bytes was introduced in Python2.6. But note that in 2.6 bytes is different and serves a different purpose than 3.x bytes. The most accurate and a concise explaination of inclusion of bytes in Python2.6 is given in what's new 2.6 document.