{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Объектно-ориентированное программирование и информационная безопасность\n",
    "\n",
    "*Валерий Семенов, Самарский университет*\n",
    "\n",
    "<div style=\"text-align:center\"><img src=\"Python.png\" width=\"200\"></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 style=\"text-align:center; margin-top:60px\">Списки (<strong>list</strong>)</h2>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Список - это <i>изменяемая</i> упорядоченная последовательность объектов произвольных типов.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 6, 7.4, 'a', 'b', [1, 2, 'a']]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp = [1, 6, 7.4, 'a', 'b', [1,2,'a']]\n",
    "sp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(sp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['P', 'y', 't', 'h', 'o', 'n']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = list('Python')  # Преобразование строки в список\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Список (в отличие от строки) это изменяемая последовательнось.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['c', 6, 7.4, 'a', 'b', [1, 2, 'a']]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp[0] = 'c'\n",
    "sp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['c', 6, 7.4, 'a']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp[:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'b', [1, 2, 'a']]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp[3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 'a', 1, 2, 'a']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [1, 2, 'a']\n",
    "a*2  # повторение"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 in a  # проверка на вхождение"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 not in a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 'a', 'b', 'c']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a + ['b', 'c']  # склеивание (конкатена́ция)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3 style=\"text-align:center; margin-top:20px\">Ошибка новичков</h3>\n",
    "    \n",
    "<div style=\"text-indent:30px; text-align:justify\">Пускай у нас есть какой-то список и мы хотим с ним сделать какие-то манипуляции, сохранив исходную копию.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 'Привет', 5.4, 'a']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [1, 2, 'Привет', 5.4, 'a']\n",
    "b = a\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 'Привет', 5.4, 'a']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 2, 'Привет', 5.4, 'a']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b[0] = 3\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 2, 'Привет', 5.4, 'a']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Ошибка в том, что и переменная <strong>a</strong> и переменная <strong>b</strong> ссылаются на один и тот же объект (<i>смотрите блокнот предыдущей лекции</i>):</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1756537177408, 1756537177408)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id(a), id(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a is b  # Проверка объектов на идентичность"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3 style=\"text-align:center; margin-top:20px\">Правильные способы копирования списков</h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1756537190720"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = [1, 2, 3]\n",
    "id(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1756537262976"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = list(x)\n",
    "id(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 'Привет', 5.4, 'a'] ['bcd', 2, 'Привет', 5.4, 'a']\n"
     ]
    }
   ],
   "source": [
    "# 1 вариант\n",
    "a = [1, 2, 'Привет', 5.4, 'a']\n",
    "b = list(a)  # теперь b ссылается на другой объект\n",
    "b[0] = 'bcd'\n",
    "print(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 'Привет', 5.4, 'a'] ['bcd', 2, 'Привет', 5.4, 'a']\n"
     ]
    }
   ],
   "source": [
    "# 2 вариант\n",
    "a = [1, 2, 'Привет', 5.4, 'a']\n",
    "b = a[:]\n",
    "b[0] = 'bcd'\n",
    "print(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 'Привет', 5.4, 'a'] ['bcd', 2, 'Привет', 5.4, 'a']\n"
     ]
    }
   ],
   "source": [
    "# 3 вариант\n",
    "a = [1, 2, 'Привет', 5.4, 'a']\n",
    "b = a.copy()\n",
    "b[0] = 'bcd'\n",
    "print(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a is b  # Проверка объектов на идентичность"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Списки могут иметь неограниченную вложенность:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[1, 3, 5], [5, 8, [1, 2]], [4, 9]]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = [[1, 3, 5], [5, 8, [1,2]], [4, 9]]\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[0][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[1][2][1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 style=\"text-align:center; margin-top:60px\">Кортежи (<strong>tuple</strong>)</h2>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Кортеж - это <i>неизменяемая</i> упорядоченная последовательность объектов произвольных типов.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = 1,2,\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "u = 1,\n",
    "type(u)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = 1\n",
    "type(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = (1,2,3)\n",
    "type(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 3, [1, 2.3], 'abc')"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = (4, 3, [1, 2.3], 'abc')\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[33], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m a[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "a[0] = 1  # Кортежи - неизменяемый тип (как строки)!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Для изменения одного элемента кортежа (как и для изменения одного символа строки), мы можем преобразовать кортеж в список, а после изменения, преобразовать список обратно в кортеж. </div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 3, [1, 2.3], 'abc']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = list(a)  # преобразуем в список\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 3, [1, 2.3], 'abc']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[0] = 1\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 3, [1, 2.3], 'abc')"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = tuple(a)  # преобразуем в кортеж\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Кортежи индексируются также как списки.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, (1, 2, (1, 2, 5)))"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = (1, (1,2,(1,2,5)))\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[1][2][2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Кортежи можно использовать для того, чтобы поменять местами значения двух переменных:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abc'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a1 = 'zxc'\n",
    "a2 = 'abc'\n",
    "a1, a2 = a2, a1\n",
    "a1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, (1, 2, (1, 2, 5)), 1, (1, 2, (1, 2, 5)))"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, (1, 2, (1, 2, 5)), 7)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x + (7,)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 in x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10 not in x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 4, 'w')"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = [1, 4, 'w']\n",
    "z = tuple(y)\n",
    "z"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 style=\"text-align:center; margin-top:20px\">Диапазоны (<strong>range</strong>)</h2>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Функция <strong>range()</strong> является встроенной функцией, которая создает объект в виде <i>неизменяемой</i> упорядоченной последовательности целых чисел внутри определенного диапазона. </div>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Записывается в следующем виде: <strong>range(начало</strong> (<i>может отсутствовать</i>)<strong>, конец</strong> (<i>не включительно</i>)<strong>, шаг </strong>(<i>может отсутствовать</i><strong>)</strong>.</div>\n",
    "    \n",
    "<div style=\"text-indent:30px; text-align:justify\">Последовательность начинается с <strong>0</strong> (если не указано <strong>начало</strong>), последовательно увеличивается на <strong>1</strong> (если не указан <strong>шаг</strong>) и заканчивается перед заданным числом (<strong>конец</strong> - обязательный параметр). </div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5)  # Задоно только конечное значение, которое не включается"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 in range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(5, 10)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = range(5,10)\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5, 10))  # Выведем диапазон в виде списка"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in r:    # Выведем значения последовательности с помощью цикла\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Также как и любая другая последовательность, диапазон поддерживает индексацию, срезы, проверку вхождения и т.п.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(5, 8)"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r[0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 in r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 not in r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[15, 14, 13, 12, 11, 10, 9, 8, 7, 6]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(15, 5, -1))  # Выведем обратный диапазон в виде списка"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 style=\"text-align:center; margin-top:20px\">Словари (<strong>dict</strong>)</h2>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Словарь - это <i>изменяемое отображение</i>.</div>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Словарь (<strong>dict</strong>, сокращение от <i>dictionary</i>) — это неупорядоченная (в отличие от списка) структура данных, которая имеет вид «ключ — значение».</div>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Говоря проще, любой словарь напоминает записную книжку без определенного порядка, где каждый номер (значение) соотнесен с конкретным именем (ключ).</div>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">При этом ключи в словарях уникальны, а значения могут повторяться. Условно говоря, дизайнеру Пете может принадлежать сколько угодно номеров — но у каждого номера может быть только один владелец.</div>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">В словаре можно хранить все что угодно: названия песен, имена покупателей, товары в интернет-магазине и так далее. </div>\n",
    "    \n",
    "<div style=\"text-indent:30px; text-align:justify\">Поскольку словарь — это неупорядоченная структура данных, все пары «ключ — значение» хранятся в произвольном порядке.</div>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Словари оформляются фигурными скобками. Внутри них находятся пары «ключ — значение». Первым пишется ключ, а затем, через двоеточие, — значение. Сами пары отделяются друг от друга запятыми:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = {\"Цвет-1\": 'Red', \"Цвет-2\": 'Blue'}\n",
    "type(d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Если нам известен ключ, можно быстро извлечь из словаря его значение — для этого используйте квадратные скобки:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Blue'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d[\"Цвет-2\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Цвет-2'"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = {'Red' : \"Цвет-1\", 'Blue': \"Цвет-2\"}\n",
    "d['Blue']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Если указать неправильный ключ, мы получим ошибку:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "1",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[61], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m d[\u001b[38;5;241m1\u001b[39m]\n",
      "\u001b[1;31mKeyError\u001b[0m: 1"
     ]
    }
   ],
   "source": [
    "d[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4 style=\"text-align:center; margin-top:20px\">Как добавить новый элемент в словарь</h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Red': 'Цвет-1', 'Blue': 'Цвет-2', 'Green': 3}"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d['Green'] = 3\n",
    "d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4 style=\"text-align:center; margin-top:20px\">Вложенность словарей</h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "users = {\"Tom\": {\n",
    "    \"phone\": \"+786532469\",\n",
    "    \"email\": \"tom1@gmail.com\"},\n",
    "        \"Bob\":{\n",
    "    \"phone\": {\"mob\": \"+65435680\", \"home\": \"224583\"},\n",
    "    \"email\": \"booob@gmail.com\"}\n",
    "        }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'tom1@gmail.com'"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users[\"Tom\"][\"email\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'+65435680'"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users[\"Bob\"][\"phone\"][\"mob\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Tom' in users"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'phone' not in users['Tom']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 style=\"text-align:center; margin-top:20px\">Множества (<strong>set</strong>)</h2>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Множество - это <i>изменяемая неупорядоченная</i>  коллекция (набор) <strong><i>уникальных</i></strong> элементов.</div>\n",
    "\n",
    "<h6 style=\"text-indent:30px; text-align:justify\">Представьте, что вы пришли на пляж и собрали в пакет коллекцию ракушек — каждая ракушка отличается от другой и не имеет четко обозначенного места в пакете. Такую коллекцию можно назвать множеством.</h6> \n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Так как элементы множества должны быть уникальны, мы можем использовать их для удаления дубликатов.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5}"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = {1, 2, 3, 3, 1, 5, 4}  # Создаем множество с помощью фигурных скобок\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Так как множества неупорядоченны, вы не сможете получить элемент по индексу, как в случае с кортежами и списками. </div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'set' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[69], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m s[\u001b[38;5;241m2\u001b[39m]\n",
      "\u001b[1;31mTypeError\u001b[0m: 'set' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "s[2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4 style=\"text-align:center; margin-top:20px\">Какие объекты можно добавить в множество</h4>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Множества могут содержать только неизменяемые объекты:</div>\n",
    "\n",
    "<div style=\" margin-left:50px\">\n",
    "<li style=\"text-align:justify\">целые числа (integer);</li>\n",
    "<li style=\"text-align:justify\">числа с плавающей точкой (float);</li>\n",
    "<li style=\"text-align:justify\">строки (string);</li>\n",
    "<li style=\"text-align:justify\">кортежи (tuple).</li>    \n",
    "</div>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Именно поэтому объектами множества не могут быть списки (list), словари (dict), и другие типы данных, которые могут перезаписываться во время работы программы.</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Для создания множества можно использовать встроенную функцию <strong>set()</strong>. </div>\n",
    "    \n",
    "<div style=\"text-indent:30px; text-align:justify\">Она принимает один аргумент — итерируемый (перебираемый) объект (список, кортеж, строку или другой объект) — и возвращает множество его элементов. </div>\n",
    "    \n",
    "<div style=\"text-indent:30px; text-align:justify\">Чтобы создать пустую коллекцию, используется <strong>set()</strong> без аргументов. </div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 3, 4, 6}"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_list = [1,3,4,1,6,3,1]\n",
    "my_set = set(my_list)  # Создаем множество из списка\n",
    "my_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{' ', '!', ',', 'H', 'W', 'd', 'e', 'l', 'o', 'r'}"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_string = \"Hello, World!\"\n",
    "my_set = set(my_string)  # Создаем множество из строки\n",
    "my_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5}"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple = (1, 2, 2, 3, 4, 5, 5)\n",
    "my_set = set(my_tuple)  # Создаем множество из кортежа\n",
    "my_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5}"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_range = range(1, 6)\n",
    "my_set = set(my_range)  # Создаем множество из диапазона\n",
    "my_set"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Из числа множество создать не удастся — предварительно надо будет превратить его в строку с помощью функции <strong>set()</strong>:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'3', '2', '5', '0', '1', '8', '9', '7'}\n"
     ]
    }
   ],
   "source": [
    "my_num = 101598723\n",
    "my_set = set(str(my_num))\n",
    "print(my_set) # Результат: {'7', '3', '8', '5', '0', '1', '2', '9'}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Если попробовать сделать множество из словаря, сохранятся только его ключи — значения в набор не войдут:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'b', 'c'}"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict1 = {'a': 1, 'b': 2, 'c': 3}\n",
    "my_set= set(dict1)\n",
    "my_set"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 style=\"text-align:center; margin-top:20px\">Замороженное множество (<strong>frozenset</strong>)</h2>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Единственное отличие <strong>set</strong> от <strong>frozenset</strong> заключается в том, что <strong>set</strong> - изменяемый тип данных, а <strong>frozenset</strong> - нет. Примерно похожая ситуация с списками и кортежами.</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "frozenset"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_set = frozenset([1, 2, 3, 4, 5])  # Создание замороженного множества\n",
    "type(my_set)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3 style=\"text-align:center; margin-top:20px\">Операторы для работы с множествами</h3>\n",
    "\n",
    "<div style=\" margin-left:50px\">\n",
    "<li style=\"text-align:justify\"><strong>a | b</strong> – объединяет два множества,</li>\n",
    "<li style=\"text-align:justify\"><strong>a |= b</strong> – добавляют элементы множества b во множество a,</li>\n",
    "<li style=\"text-align:justify\"><strong>a - b</strong> – вычисляет разницу множеств,</li>\n",
    "<li style=\"text-align:justify\"><strong>a -= b</strong> – удаляют элементы из множества a, которые существуют и во множестве a, и во множестве b,</li>\n",
    "<li style=\"text-align:justify\"><strong>a & b</strong> – пересечение множеств. Позволяет получить элементы, которые существуют в обоих множествах.</li>\n",
    "<li style=\"text-align:justify\"><strong>a &= b</strong> – во множестве а останутся элементы, которые существуют и во множестве a, и во множестве b,</li>\n",
    "<li style=\"text-align:justify\"><strong>a ^ b</strong> – возвращает все элементы обоих множеств, исключая элементы, которые присутствуют в обоих этих множествах,</li>\n",
    "<li style=\"text-align:justify\"><strong>a ^= b</strong> и – во множестве a будут все элементы обоих множеств, исключая те, что присутствуют в обоих этих множествах,</li>\n",
    "<li style=\"text-align:justify\"><strong>in</strong> – проверка наличия элемента во множестве,</li>\n",
    "<li style=\"text-align:justify\"><strong>not in</strong> – проверка отсутствия элемента во множестве,</li>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = {1, 2, 3, 3, 1, 5, 4}\n",
    "ss = {10, 4, 8, 2}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{2, 4}"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Пересечение множеств\n",
    "s & ss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5, 8, 10}"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Объединение множеств\n",
    "ss | s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Проверка наличия элемента во множестве\n",
    "2 in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Проверка отсутствия элемента во множестве\n",
    "8 not in ss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1 style=\"text-align:center; margin-top:40px\">Ввод и вывод данных</h1>\n",
    "\n",
    "<div style=\"text-indent:30px; text-align:justify\">Для ввода данных с клавиатуры предназначена функция <strong>input()</strong>:</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Введите ваше имя  Иванопуло\n"
     ]
    }
   ],
   "source": [
    "name = input('Введите ваше имя ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Иванопуло'"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Абвгд\n"
     ]
    }
   ],
   "source": [
    "# input() считывает данные в строковом типе!\n",
    "a = input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Абвгд'"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 12.345\n",
      " 50\n"
     ]
    }
   ],
   "source": [
    "a = input()\n",
    "b = input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'12.34550'"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 12.345\n",
      " 50\n"
     ]
    }
   ],
   "source": [
    "a = float(input())  # Ввод числа с плавающей точкой\n",
    "b = int(input())    # Ввод целого числа"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "62.345"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a + b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-indent:30px; text-align:justify\">Для вывода данных используется функция <strong>print()</strong></div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "print(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "56 str\n"
     ]
    }
   ],
   "source": [
    "a = 56\n",
    "b = 'str'\n",
    "print(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет! Hello!\n"
     ]
    }
   ],
   "source": [
    "print('Привет!', 'Hello!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет!\n",
      "Hello!\n"
     ]
    }
   ],
   "source": [
    "print('Привет!', 'Hello!', sep = '\\n')  # sep = задает разделитель между объектами, по умолчанию = Пробел. \\n - перевод строки."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет Hello!\n"
     ]
    }
   ],
   "source": [
    "print('Привет', end = ' ')  # end = указывает на то, чем заканчивается вывод. По умолчанию - перевод строки.\n",
    "print('Hello!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Как тебя зовут?  Вася\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет, Вася\n"
     ]
    }
   ],
   "source": [
    "print(\"Привет,\", input(\"Как тебя зовут? \"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
