1, Bytes and ByteArray
# bytes: immutable byte sequence; ByteArray: byte array, variable data type;
(1) Bytes definition
class bytes (object): """ (1) bytes (iterable_of_ints), Bytes (2) bytes (string, encoding[, errors]), Bytes (3) bytes ( Bytes_or_buffer)-Immutable copy of Bytes_or_buffer (4) bytes (int), bytes object of size given by the Paramet Er initialized with null bytes # Specifies the byte of the bytes, which is filled by 0;
B=bytes # Create a 10-byte bytes;
Print (b) # ==> B ' \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 '; (5) bytes (), empty bytes Object # Create a null bytes;
# Note: The bytes type, defined using the B prefix;
Only allow ASCII-based use of string form B ' abc9 ' representation
Use 16 binary to represent B ' \x41\x61 '
(2) ByteArray definition
class ByteArray (object): """ ByteArray (iterable_of_ints), ByteArray ByteArray (String, encoding[, errors]), ByteArray ByteArray (bytes_or_buffer), mutable copy of Bytes_or_buffer bytearray (int), bytes array of size given by the parameter initialized with null bytes ByteArray (), empty bytes array
# B=bytearray (5)
# print (b) # ByteArray (b ' \x00\x00\x00\x00\x00 ')
2. Character encoding
Python Learning Python Basics week4-2