Python 3 : Convert string to bytes
By:Roy.LiuLast updated:2019-08-17
Code snippets to show you how to convert string to bytes and vice versa.
1. To convert a string to bytes.
data = "" #string data = "".encode() #bytes data = b"" #bytes
2. To convert bytes to a String.
data = b"" #bytes data = b"".decode() #string data = str(b"") #string
P.S Tested with Python 3.4.3
From:一号门
COMMENTS