The following editor will bring you an articlepythonStringstr and bytearraymutual conversion method. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
The examples are as follows:
##
# bytes object b = b"example" # str object s = "example" # str to bytes bytes(s, encoding = "utf8") # bytes to str str(b, encoding = "utf-8") # an alternative method # str to bytes str.encode(s) # bytes to str bytes.decode(b)
The above is the detailed content of Detailed introduction to the mutual conversion method of python string str and byte array. For more information, please follow other related articles on the PHP Chinese website!