python的数据类型转换

#编码:
#py3中只有2种数据类型:str , bytes
# str: unicode形式
# bytes: 16进制 (更底层) 有utf8,gbk,gb2312 等等类型


#s='hi 范'

# 编码: str ---> bytes
# sb1 = bytes(s,'utf-8')
# sb2 = s.encode('utf8')

# 解码: bytes --> str
# s1 = str(sb1,'utf8') #前面sb1 是utf8形式的,所以这要写utf8才不乱码
# s2 = sb1.decode('utf8')

"""
str
| ^
编码encode .bytes | | 解码decode . str (解码成什么类型看你编码的是什么类型)
V |
bytes
"""

#note:
#windows系统默认按照gbk编码的
#python3中socket 编程中 传输的要是bytes类型
原文地址:https://www.cnblogs.com/fanxuanhui-linux/p/7726157.html