Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> xs = 'ahoj' >>> xb = b'ahoj' >>> xs 0: 'ahoj' >>> xb 1: b'ahoj' >>> for x in xs: ... print(x) a h o j >>> for x in xb: ... print(x) 97 104 111 106 >>> yb = bytearray([33, 44, 55, 66, 77, 88, 99, 111, 122, 133, 144, 155]) >>> yb 2: bytearray(b'!,7BMXcoz\x85\x90\x9b') >>> int('85', 16) 3: 133 >>> for y in yb: ... print(y) 33 44 55 66 77 88 99 111 122 133 144 155 >>> yb = bytearray([33, 44, 55, 66, 77, 88, 99, 111, 122, 133, 144, 155, 255]) >>> yb 4: bytearray(b'!,7BMXcoz\x85\x90\x9b\xff') >>> yb = bytearray([33, 44, 55, 66, 77, 88, 99, 111, 122, 133, 144, 155, 255, 256]) Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> yb = bytearray([33, 44, 55, 66, 77, 88, 99, 111, 122, 133, 144, 155, 255, 256]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: byte must be in range(0, 256) >>> yb[-1] 5: 255 >>> yb[-1] = b'!' Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> yb[-1] = b'!' ~~^^^^ TypeError: 'bytes' object cannot be interpreted as an integer >>> yb[-1] = 33 >>> yb[-1] 6: 33 >>> yb 7: bytearray(b'!,7BMXcoz\x85\x90\x9b!') >>> zb = bytes(yb) >>> zb 8: b'!,7BMXcoz\x85\x90\x9b!' >>> zb[-1] 9: 33 >>> zb[-1] = 255 Traceback (most recent call last): File "<pyshell#21>", line 1, in <module> zb[-1] = 255 ~~^^^^ TypeError: 'bytes' object does not support item assignment >>> dir(yb) 10: ['__add__', '__alloc__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'capitalize', 'center', 'clear', 'copy', 'count', 'decode', 'endswith', 'expandtabs', 'extend', 'find', 'fromhex', 'hex', 'index', 'insert', 'isalnum', 'isalpha', 'isascii', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'pop', 'remove', 'removeprefix', 'removesuffix', 'replace', 'reverse', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> dir(zb) 11: ['__add__', '__bytes__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'center', 'count', 'decode', 'endswith', 'expandtabs', 'find', 'fromhex', 'hex', 'index', 'isalnum', 'isalpha', 'isascii', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> bytes() 12: b'' >>> bytes(3) 13: b'\x00\x00\x00' >>> bytes([3]) 14: b'\x03' >>> bytes({3}) 15: b'\x03' >>> bytes((3)) 16: b'\x00\x00\x00' >>> bytes((3,)) 17: b'\x03' >>> yb 18: bytearray(b'!,7BMXcoz\x85\x90\x9b!') >>> '!' in yb Traceback (most recent call last): File "<pyshell#31>", line 1, in <module> '!' in yb TypeError: a bytes-like object is required, not 'str' >>> b'!' in yb 19: True >>> 33 in yb 20: True >>> yb[-1] 21: 33 >>> yb[-1:] 22: bytearray(b'!') >>> zb[-1] 23: 33 >>> zb[-1:] 24: b'!' >>> b'a{}c'.format(33) Traceback (most recent call last): File "<pyshell#38>", line 1, in <module> b'a{}c'.format(33) ^^^^^^^^^^^^^^ AttributeError: 'bytes' object has no attribute 'format' >>>