Python 3 : Convert string to bytes
摘要: Code snippets to show you how to convert string to bytes and vice versa.
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