Home  >  Article  >  Backend Development  >  Detailed introduction to the mutual conversion method of python string str and byte array

Detailed introduction to the mutual conversion method of python string str and byte array

高洛峰
高洛峰Original
2017-03-20 09:20:341626browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn