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

python字符串str和字节数组相互转化

2015-01-29 15:17 423 查看
s="'2014/9/18 23:16:34'"

c = bytearray(str(s).encode("gbk"))

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