Home > Backend Development > Python Tutorial > 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

高洛峰
Release: 2017-03-20 09:20:34
Original
1639 people have browsed it

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)
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template