#Протокол по Теме 2 Анисенков Павел Дмитриевич import os os.chdir('C:\\Users\\Professional\\Desktop\\python-labs\\Tema2') f1=16; f2=3 f1,f2 (16, 3) dir(f1) ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'as_integer_ratio', 'bit_count', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'is_integer', 'numerator', 'real', 'to_bytes'] type(f2) del f1,f2 f1,f2 Traceback (most recent call last): File "", line 1, in f1,f2 NameError: name 'f1' is not defined gg1=1.6 hh1='Строка' 73sr=3 SyntaxError: invalid decimal literal and=7 SyntaxError: invalid syntax import keyword keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] spis='['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']' SyntaxError: invalid syntax spis=['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] import builtins dir(builtins) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BaseExceptionGroup', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EncodingWarning', 'EnvironmentError', 'Exception', 'ExceptionGroup', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'PythonFinalizationError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '_IncompleteInputError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'aiter', 'all', 'anext', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'] print(abs(-5)) 5 print(len("Hello")) 5 print(len([1, 2, 3])) 3 print(max(1, 5, 3)) 5 print(min([10, 20, 5])) 5 print(pow(5, 2)) 25 print(pow(4, 0.5)) 2.0 print(round(3.14159)) 3 print(round(2.675, 2)) 2.67 print(sorted("hello")) ['e', 'h', 'l', 'l', 'o'] 2 print(sorted(numbers)) [1, 2, 3, 4] print(sorted(numbers, reverse=True)) [4, 3, 2, 1] names = ["Alice", "Bob"] ages = [25, 30] pop = zip(names, ages) print(list(pop)) [('Alice', 25), ('Bob', 30)] print(type(5)) print(type("hello")) print(type([1, 2, 3])) print(dir("hello")) ['__add__', '__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', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', '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'] Gg1=45 print(gg1,Gg1) 1.6 45 bb1 = True; bb2 = False bb1,bb2 (True, False) type(bb1) ii1=-1234567890 ff1=-8.9876e-12 dv1=0b1101010 vsm1-0o52765 Traceback (most recent call last): File "", line 1, in vsm1-0o52765 NameError: name 'vsm1' is not defined vsm1=0o52765 shest1=0x7109af6 cc1=2-3j a=3.67;b=-0.45 cc2=complex(a,b) ss1 Traceback (most recent call last): File "", line 1, in ss1 NameError: name 'ss1' is not defined ss1='Это - строка символов' ss1a="Это - \" строка символов \", \n \t выводимая на двух строках" ss1a 'Это - " строка символов ", \n \t выводимая на двух строках' ss1b= 'Меня зовут: \n Анисенков П. Д.' ыы1и Traceback (most recent call last): File "", line 1, in ыы1и NameError: name 'ыы1и' is not defined ss1b 'Меня зовут: \n Анисенков П. Д.' print(ss1b) Меня зовут: Анисенков П. Д. print(ss1a) Это - " строка символов ", выводимая на двух строках mnogo="""Нетрудно заметить , что в результате операции над числами разных типов получается число, имеющее более сложный тип из тех, которые участвуют в операции.""" print(mnogo) Нетрудно заметить , что в результате операции над числами разных типов получается число, имеющее более сложный тип из тех, которые участвуют в операции. ss1[0] 'Э' ss1[8] 'р' ss1[-2] 'о' ss1[6:9] 'стр' ss1[13:] 'символов' ss1[:13] 'Это - строка ' ss1[5:-8] ' строка ' ss1[3:17:2] ' тоасм' ss1[17:3:-2] 'омсаот ' ss1[-4:3:-2] 'омсаот ' ss1[4] '-' ss1=ss1[:4]+'='+ss1[5:] slice1 = ss1b[:10] slice1 'Меня зовут' slice2 = ss1b[12:] slice2 '\n Анисенков П. Д.' slice5 = ss1b[::2] slice5 'Мн оу:\nАиеквП .' spis1=[111,'Spisok',5-9j] stup=[0,0,1,1,1,1,1,1,1] spis=[1,2,3,4, 5,6,7, 8,9,10] spis1[-1] (5-9j) stup[-8::2] [0, 1, 1, 1] spis1[1]='Список' print(spis1) [111, 'Список', (5-9j)] len(spis1) 3 help(spis1.append) Help on built-in function append: append(object, /) method of builtins.list instance Append object to the end of the list. spis1+['New item'] [111, 'Список', (5-9j), 'New item'] spis1+'ss1b' Traceback (most recent call last): File "", line 1, in spis1+'ss1b' TypeError: can only concatenate list (not "str") to list spis1+['ss1b'] [111, 'Список', (5-9j), 'ss1b'] spis1+ss1b Traceback (most recent call last): File "", line 1, in spis1+ss1b TypeError: can only concatenate list (not "str") to list spis1.pop(1) 'Список' spis1 [111, (5-9j)] spis2=[spis1,[4,5,6,7]] spis2[0][1] (5-9j) spis2[0][1]=78 spis1 [111, 78] spisk=[20,'Pavel',0.4532] spisk+ [1,2,3,4,5],{"имя":"Павел", "возраст": 20} ([20, 'Pavel', 0.4532, 1, 2, 3, 4, 5], {'имя': 'Павел', 'возраст': 20}) kort1=(222,'Kortezh',77+8j) kort1= kort1+(1,2) kort1 (222, 'Kortezh', (77+8j), 1, 2) kort1= kort1+(ss1b,) kort1 (222, 'Kortezh', (77+8j), 1, 2, 'Меня зовут: \n Анисенков П. Д.') kort2=kort1[:2]+kort1[3:] kort1.index(2) 4 kort1.count(222) 1 kort1[2]=90 Traceback (most recent call last): File "", line 1, in kort1[2]=90 TypeError: 'tuple' object does not support item assignment my_tuple = ( 42, # целое число "Привет", # строка [1, 2, 3], # список (4, 5, 6) #кортеж ) dic1={'Saratov':145, 'Orel':56, 'Vologda':45} dic1['Orel'] 56 dic1['Pskov']=78 вшс1 Traceback (most recent call last): File "", line 1, in вшс1 NameError: name 'вшс1' is not defined dic1 {'Saratov': 145, 'Orel': 56, 'Vologda': 45, 'Pskov': 78} sorted(dic1.keys()) ['Orel', 'Pskov', 'Saratov', 'Vologda'] sorted(dic1.values()) [45, 56, 78, 145] dic2={1:'mean',2:'standart deviation',3:'correlation'} dic3={'statistics':dic2,'POAS':['base','elementary','programming']} dic3['statistics'][2] 'standart deviation' dic4=dict([(1,['A','B','C']),(2,[4,5]),('Q','Prim'),('Stroka',ss1b)]) spska = ('яблоко', 'банан', 'апельсин', 'виноград', 'киви', 'манго', 'груша') spysk = [10, 20, 30, 40, 50] res = dict(zip(spska, spysk)) res {'яблоко': 10, 'банан': 20, 'апельсин': 30, 'виноград': 40, 'киви': 50} mnoz1={'двигатель','датчик','линия связи','датчик','микропроцессор','двигатель'} mnoz1 {'линия связи', 'датчик', 'двигатель', 'микропроцессор'} len(mnoz1) 4 'датчик' in mnoz1 True mnoz1.add('реле') mnoz1 {'линия связи', 'датчик', 'двигатель', 'реле', 'микропроцессор'} mnoz1.remove('линия связи') mnoz1 {'датчик', 'двигатель', 'реле', 'микропроцессор'} set123= { 42, # целое число 3.14, # число с плавающей точкой "Привет", # строка (1, 2, 3), # кортеж True, # логическое значение "Python", # еще строка frozenset([7, 8, 9]), # неизменяемое множество 42 # дубликат (будет удален) } set123.add([7, 8, 9]) Traceback (most recent call last): File "", line 1, in set123.add([7, 8, 9]) TypeError: unhashable type: 'list' my_set.remove("Привет") Traceback (most recent call last): File "", line 1, in my_set.remove("Привет") NameError: name 'my_set' is not defined set123.remove("Привет") set123 {True, 3.14, 42, (1, 2, 3), 'Python', frozenset({8, 9, 7})}