Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> xs = 'ahoj' >>> xb = b'ahoj' >>> for x in xs: ... print(x) a h o j >>> for x in xb: ... print(x) 97 104 111 106 >>> chr(97) 0: 'a' >>> dir(xb) 1: ['__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'] [About 76 more lines. Double-click to unfold] >>> xb[0] 2: 97 >>> xb[0] == 97 3: True >>> xb[0] == 'a' 4: False >>> xb[0] == b'a' 5: False >>> xb[0:2] 6: b'ah' >>> type(xb[0:2]) 7: <class 'bytes'> >>> type(xb[0]) 8: <class 'int'> >>> xs 9: 'ahoj' >>> xs[0] = 'A' Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> xs[0] = 'A' ~~^^^ TypeError: 'str' object does not support item assignment >>> xb 10: b'ahoj' >>> xb[0] = b'A' Traceback (most recent call last): File "<pyshell#16>", line 1, in <module> xb[0] = b'A' ~~^^^ TypeError: 'bytes' object does not support item assignment >>> bytes() 11: b'' >>> bytes('Ahoj!', 'utf-8') 12: b'Ahoj!' >>> bytes('Ahoj!', 'windows-1250') 13: b'Ahoj!' >>> bytes(7) 14: b'\x00\x00\x00\x00\x00\x00\x00' >>> b'\x07' 15: b'\x07' >>> int('10', 8) 16: 8 >>> int('100', 2) 17: 4 >>> int('A', 16) 18: 10 >>> int('a', 16) 19: 10 >>> int('10', 16) 20: 16 >>> int('ff', 16) 21: 255 >>> int('FF', 16) 22: 255 >>> hex(255) 23: '0xff' >>> oct(255) 24: '0o377' >>> bin(255) 25: '0b11111111' >>> b'0o377' 26: b'0o377' >>> for x in b'0o377': print(x) 48 111 51 55 55 >>> for x in b'\o377': print(x) 92 111 51 55 55 >>> for x in b'\xff': print(x) 255 >>> bytes([7]) 27: b'\x07' >>> bytes((7,)) 28: b'\x07' >>> bytes({7}) 29: b'\x07' >>> b'ahoj'.capitalize() 30: b'Ahoj' >>> b'ahoj ahoj'.capitalize() 31: b'Ahoj ahoj' >>> b'ahoj ahoj'.title() 32: b'Ahoj Ahoj' >>> xb 33: b'ahoj' >>> b'hoj' in xb 34: True >>> b'h' in xb 35: True >>> ord('h') 36: 104 >>> 104 in xb 37: True >>> xb * 2 38: b'ahojahoj' >>> 2 * xb 39: b'ahojahoj' >>> for x in xb: ... print(x) 97 104 111 106 >>> for x in sorted(xb): ... print(x) 97 104 106 111 >>> for x in reversed(xb): ... print(x) 106 111 104 97 >>> for x in reversed(xb): ... print(x, chr(x)) 106 j 111 o 104 h 97 a >>> for x in enumerate(xb): ... print(x) (0, 97) (1, 104) (2, 111) (3, 106) >>> for x in enumerate(xb, start=1): ... print(x) (1, 97) (2, 104) (3, 111) (4, 106) >>> for i,x in enumerate(xb, start=1): ... print(i, x, sep='|') 1|97 2|104 3|111 4|106 >>> b"ahoj" 40: b'ahoj' >>> b'''ahoj ... Baf! ... ''' 41: b'ahoj\nBaf!\n' >>> yb = b'''ahoj ... Baf! ... ''' >>> for y in yb: ... print(y, end=' ') 97 104 111 106 10 66 97 102 33 10 >>> for y in yb: ... print(y, chr(y)) 97 a 104 h 111 o 106 j 10 66 B 97 a 102 f 33 ! 10 >>> yb 42: b'ahoj\nBaf!\n' >>> f'{xs}' 43: 'ahoj' >>> b'{xb}'.format(b'ahoj') Traceback (most recent call last): File "<pyshell#63>", line 1, in <module> b'{xb}'.format(b'ahoj') ^^^^^^^^^^^^^^ AttributeError: 'bytes' object has no attribute 'format' >>> b'%c' % 97 44: b'a' >>> b'%c' % (97, ) 45: b'a' >>> b'%c %c' % (97, 98) 46: b'a b' >>> '狼.cz'.encode('big5') 47: b'\xafT.cz' >>> int('af', 16) 48: 175 >>> ord('T') 49: 84 >>> ord('.') 50: 46 >>> ord('c') 51: 99 >>> ord('z') 52: 122 >>> xs 53: 'ahoj' >>> f'{xs}' 54: 'ahoj' >>> f'{{xs}}' 55: '{xs}' >>> bytearray([65, 66, 67]) 56: bytearray(b'ABC') >>> zb = bytearray([65, 66, 67]) >>> type(zb) 57: <class 'bytearray'> >>> dir(zb) 58: ['__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'] [About 87 more lines. Double-click to unfold] >>> zb 59: bytearray(b'ABC') >>> zb[0] 60: 65 >>> zb[0] = 97 >>> zb 61: bytearray(b'aBC') >>> zb.pop(0) 62: 97 >>> zb 63: bytearray(b'BC') >>> zb.append(b'A') Traceback (most recent call last): File "<pyshell#86>", line 1, in <module> zb.append(b'A') TypeError: 'bytes' object cannot be interpreted as an integer >>> zb.append(65) >>> zb 64: bytearray(b'BCA') >>> zb.extend(b'A') >>> zb 65: bytearray(b'BCAA') >>> zb.extend(b'abc') >>> zb 66: bytearray(b'BCAAabc') >>> zb[-1] 67: 99 >>> zb 68: bytearray(b'BCAAabc') >>> zb + b'ABC' 69: bytearray(b'BCAAabcABC') >>> zb 70: bytearray(b'BCAAabc') >>> zb[-3:] 71: bytearray(b'abc') >>> del zb[-3:] >>> zb 72: bytearray(b'BCAA') >>> ord('A') 73: 65 >>> zb.remove('65') Traceback (most recent call last): File "<pyshell#101>", line 1, in <module> zb.remove('65') TypeError: 'str' object cannot be interpreted as an integer >>> zb.remove(65) >>> zb 74: bytearray(b'BCA') >>> zb.remove(b'A') Traceback (most recent call last): File "<pyshell#104>", line 1, in <module> zb.remove(b'A') TypeError: 'bytes' object cannot be interpreted as an integer >>> int('10101010', 2) 75: 170 >>> int('01010101', 2) 76: 85 >>> int('1010101', 2) 77: 85 >>> chr(170) 78: 'ª' >>> chr(85) 79: 'U' >>> int('10000000', 2) 80: 128 >>> int('01000000', 2) 81: 64 >>> int('1000000', 2) 82: 64 >>> int('10111111', 2) 83: 191 >>> int('01111111', 2) 84: 127 >>> int('1111111', 2) 85: 127 >>> 2000 / 256 86: 7.8125 >>> 2000 // 256 87: 7 >>> 2000 - (2000 // 256) * 256 88: 208 >>> 7 * 256 + 208 89: 2000 >>> 208 * 256 + 7 90: 53255 >>> 0b1010 << 1 91: 20 >>> int(0b1010 << 1) 92: 20 >>> bin(0b1010 << 1) 93: '0b10100' >>> bin(0b1010 >> 1) 94: '0b101' >>> bin(0b11100000000 >> 7) 95: '0b1110' >>> bin(0b11100000000 >> 8) 96: '0b111' >>> bin(2000) 97: '0b11111010000' >>> int('11010000', 2) 98: 208 >>> int('111', 2) 99: 7 >>> 2000 % 256 100: 208 >>> bin(0b11100000000 << 8) 101: '0b1110000000000000000' >>> 'ůřá'.encode('utf-8') 102: b'\xc5\xaf\xc5\x99\xc3\xa1' >>>