# source是字符串,则使用str.encode()转换 b = bytes('abc',encoding='utf-8',errors='strict') print(b,b[0]) # bytes对象不可变 try: b[0] = 100 except TypeError as err: print('it is immutable.so',err)