Deprecated/Python

Binary to String, String to Binary

코인고블린 2018. 3. 9. 22:11

간단하다.


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