Python standard library: built-in function bytes ([source [, encoding [, errors]), pythonencoding
Returns a new array object. The array object cannot be modified. Value range of each element: 0 <= x <256. The main difference between the bytes function and the bytearray function is that the elements of the objects generated by the bytes function cannot be modified, while the elements of the objects generated by the bytearray function can be modified. Therefore, except for modifiable object functions and bytearray functions, all other usage methods are the same. Finally, Its Parameter definition method is the same as that of the bytearray function.
Example:
# Bytes () function a = bytes ('abc', 'utf-8') print (a) B = bytes (1) print (B) c = bytes ([2, 3, 6, 8]) print (c)
The output result is as follows:
B 'abc'
B '\ x00'
B '\ x02 \ x03 \ x06 \ x08'
In pthon, bytearray ([source [, encoding [, errors]) explains what are the three variables behind it?
It is written in the document. Let's take a look at several situations.
How to view built-in functions in python
Import sys
Print dir (sys. modules ['_ builtin _'])