{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3203391b",
   "metadata": {},
   "source": [
    "# 11-06 · Кортежи\n",
    "\n",
    "Практика к разделу [«Кортежи»](../../site/chapters/glava-11/11-06-kortezhi.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f26f8110",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить кортежи и распаковку."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b68bc11a",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c25fe304",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:45.627123Z",
     "iopub.status.busy": "2026-08-14T20:55:45.626979Z",
     "iopub.status.idle": "2026-08-14T20:55:45.645453Z",
     "shell.execute_reply": "2026-08-14T20:55:45.644997Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10, 20)\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "coords = (10, 20)\n",
    "print(coords)\n",
    "print(coords[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d33c5c99",
   "metadata": {},
   "source": [
    "## Типичная ошибка\n",
    "\n",
    "Кортежи неизменяемы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dcb74459",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:45.646610Z",
     "iopub.status.busy": "2026-08-14T20:55:45.646489Z",
     "iopub.status.idle": "2026-08-14T20:55:45.673636Z",
     "shell.execute_reply": "2026-08-14T20:55:45.673112Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mTypeError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m      1\u001b[39m coords = (\u001b[32m10\u001b[39m, \u001b[32m20\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m coords[\u001b[32m0\u001b[39m] = \u001b[32m99\u001b[39m\n",
      "\u001b[31mTypeError\u001b[39m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "coords = (10, 20)\n",
    "coords[0] = 99"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2540a20f",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — распаковка"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7f983b95",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:45.674653Z",
     "iopub.status.busy": "2026-08-14T20:55:45.674543Z",
     "iopub.status.idle": "2026-08-14T20:55:45.676992Z",
     "shell.execute_reply": "2026-08-14T20:55:45.676450Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 20\n"
     ]
    }
   ],
   "source": [
    "coords = (10, 20)\n",
    "x, y = coords\n",
    "print(x, y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79f7490a",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Создайте кортеж RGB-цвета (255, 0, 128) и распакуйте его в r, g, b."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dc740fac",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:45.678291Z",
     "iopub.status.busy": "2026-08-14T20:55:45.678163Z",
     "iopub.status.idle": "2026-08-14T20:55:45.680524Z",
     "shell.execute_reply": "2026-08-14T20:55:45.680141Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "r=255, g=0, b=128\n"
     ]
    }
   ],
   "source": [
    "color = (255, 0, 128)\n",
    "r, g, b = color\n",
    "print(f\"r={r}, g={g}, b={b}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "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.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
