简体   繁体   中英

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?

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 .

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> bytes()
''

Also, there's documentation to read up on: http://www.python.org/dev/peps/pep-0358/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM