您的位置:首页 > 编程语言 > Python开发

Python 3 : Convert string to bytes

2015-09-29 10:10 721 查看
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


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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: