## Консольный ввод и вывод `print([Параметры])` `Имя = input("Текст")` ```python print("Hello", " ", "World!", 32) a = "Hello" b = "World!" print(f"{a} {b} {32.0}") a = 1 a = "ffff" # a = a + 1 b = [1] ``` ## Условные выражения и логические операции ```python if условие: что-то делаем elif условие: что-то делаем else: что-то делаем ``` ```python if a == 1: print(a) ``` ## Циклы - `while` - `for` ```python while a == 1: print(a) break for t in [1, 2, 3]: print(t) ``` ## Функции ```python def Имя([Параметры]): что-то делаем def Имя([Параметры]): return что-то возвращаем lambda [Параметры]: что-то делаем lambda [Параметры]: return что-то возвращаем ``` ```python def Print(*a): for i in a: print(i) Print(1, 2, 3) def I(): i = 0 def J(): i += 1 return i v = I() def Calc(operation, a, b): print(operation(a, b)) def Plus() Calc(lambda a, b: return a + b, 1, 2) Calc(lambda a, b: return a - b, 1, 2) ``` ## Преобразование типов `Тип(Значение)` - явное преобразование ```python a = int(input("input number: ")) print(a + 1) b = 1.1 с = b + 1 print(c, c.__doc__) print(c, type(c)) ``` ## ООП ```python class Имя: атрбиуты def __init__(self): инициализатор(конструктор) методы ``` ```python class Abs: pass class A: a = 1 b = "2" @property def A(self): return self.__a @A.setter def A(self, a) def Add(self, c): a += c def Print(self): print(a, b) c = A() c.Print() d = A() c.Add(1) c.Print() d.Print() c.a = 12 print(c.a) c._c = 12 c.__a = 12 print(c._c) print(c.__a) c.A = 3 print(c.A) class B(A): def __init__(self, d) self.__d = d def Print(self): super().Print() print(self.a, self.b, self.__d) def __str__(self): return f"{self.a} {self.b} {self.__d}" a = B("Hello") a.Print() print(a) ``` ## Обработка исключений ```python try: что-то делаем except: что-то делаем finally: что-то делаем raise Exception("Тут сломалось") try: что-то делаем except Exception as e: print(e) ``` ## Структуры данных - Список: `[1, 2, 3]` - Кортеж: `(1, 2, 3)` - Диапазон: `range(10)` - Словарь: `{1:2, 2:3}` - Множество: `{1, 2, 3}`, `set(Это_список)` ```python point = (x, y) = (1, 2) print(x) print(y) print(poin, type(point)) for i in range (1, 10): print(i) s = {1, 2, 2, 3} s = set(range(10)) for i in s: print(i) ``` ## Модули ```python import math import math as Математика from math import * from math import sqrt, pow from math import pow as Степень ``` ```python import Help Help.A("Hello World!") def A(i): print(i) def Test(): print(__name__, "__main___") if(__name__ == "__main___"): Test() print(__name__) from Help2 import A from Help2 import A as B from timeit import timeit from math import * import timeit as wow A("Hello World!") B("HELLO WORLD!") ``` ## Работа с файлами ```python with open("file.txt", "w"): Что-то делаем ```