1.遍历列表提取下标和值:
for index,value in enumerate(['apple', 'oppo', 'vivo']):
print(index,value)
2.bytes 和 str 的互相转换
字符串转bytes:str.encode('utf-8')
bytes转字符串:bytes.decode('utf-8')
本文介绍了Python中如何遍历列表获取元素的下标和值,以及如何进行字符串与bytes类型之间的相互转换。通过示例代码展示了enumerate函数的使用方法,并解释了不同编码方式之间的转换过程。
1.遍历列表提取下标和值:
for index,value in enumerate(['apple', 'oppo', 'vivo']):
print(index,value)
2.bytes 和 str 的互相转换
字符串转bytes:str.encode('utf-8')
bytes转字符串:bytes.decode('utf-8')
1万+
5712
8186

被折叠的 条评论
为什么被折叠?