字符串的运算:
+ += * *=
< <= > >= == !=
in / not in
索引和切片
函数:
len(x)
max(x)
min(x)
sum(x)
any(x)
all(x)
bytes 与 str 的区别:
bytes 存储字节(0~255)
str 存储 unicode 字符(0~65535或更大)
str 与 bytes转换
编码(encode)
str ----------> bytes
b = s.encode(encoding='utf-8')
解码(decode)
bytes -------------> str
s = b.decode(encoding='utf-8')
字节数组 bytearray
可变的字节序列
创建函数bytearray
bytearray() 创建字节数组
bytearray(可迭代对象) 同bytes(可迭代对象)
bytearray(整数n) ...
bytearray(字符串, encoding='utf-8')
运算操作:
+ += * *=
比较运算: < <= > >= == !=
in / not in
索引 index / 切片 slice
(字节数组支持索引和切片赋值,规则同列表的索引和切片赋值规则)
字节数组的方法:
详见:
help(bytearray)