编码格式转换
1,id() 内存地址
2, == 比较的是值
is 比较的是内存地址
数字,字符串,有小数据池,
int -5--256
str:1,不能有空格。
2,长度不能超过20。
3,不能有特殊字符如:#@.....
3,enmurate枚举 iterable: str,list,tuple,dict,set
for i in enmurate(iterable):
pirnt(i)
for i in enmurate(['barry','alex']):
pirnt(i) # (0,'barry') (1,'alex')
for index,i in enmurate(['barry','alex']):
pirnt(index,i) # 0,'barry'
1,'alex'
for index,i in enmurate(['barry','alex'],100):
pirnt(index,i) # 100,'barry'
101,'alex'
4,编码
py3:
str:表现形式:s = 'alex' 实际编码方式:unicode
bytes:表现形式:s = b'alex' 实际编码方式:utf-8,gbk,gb2312...
s = b'\x2e\x2e\x2e\x2e\x2e\x2e'
unicode:所有字符(无论英文,中文等) 1个字符:4个字节
gbk:一个字符,英文1个字节,中文两个字节。
utf-8:英文 1 个字节,欧洲:2个字节,亚洲:3个字节。
#id 内存地址
s = 'alex' print(s,type(s)) print(s,type(s),id(s)) li = [1,2,3,] print(li,type(li),id(li)) 输出: alex <class 'str'> alex <class 'str'> 35616336 [1, 2, 3] <class 'list'> 34881672

bytes 表现形式:s = b‘alex’内部存储是(utf-8,gbk,gb2313....)0101 s1 = '黎诗' b11 = s1.encode('utf-8') 中文:表现形式: b'\xe6\x99\x93\xe6\xa2\x85' (utf-8,gbk,gb2312...)010101 0000 1000 0000 0000 0000 1000 0000 0000 0000 1000 0000 0000 s2 = '黎诗' b22 = s1.encode('gkb') print(b22) b'\xcf\xfe\xc3\xb7' 表现形式:b22 = s1.encode('gbk') print(b22) b'\xcf\xfe\xc3\xb7' 中文表现形式:s = b'\xcf\xfe\xc3\xb7' (utf-8,gbk,gb2312...)010101 0000 1000 0000 0000 0000 1000 0000 0000 str 表现形式: s = ‘alex’ 内部存储是 unicode 0101010


【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步