{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "42a30608",
   "metadata": {},
   "source": [
    "# 11-01 · Списки: основы\n",
    "\n",
    "Практика к разделу [«Списки: основы»](../../site/chapters/glava-11/11-01-spiski-osnovy.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c58cb77a",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Создавать списки и обращаться к элементам по индексу."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f08074a",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d5f6b60a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:37.270584Z",
     "iopub.status.busy": "2026-08-14T20:55:37.270473Z",
     "iopub.status.idle": "2026-08-14T20:55:37.289644Z",
     "shell.execute_reply": "2026-08-14T20:55:37.289111Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['яблоко', 'банан', 'вишня']\n",
      "яблоко\n",
      "вишня\n"
     ]
    }
   ],
   "source": [
    "fruits = [\"яблоко\", \"банан\", \"вишня\"]\n",
    "print(fruits)\n",
    "print(fruits[0])\n",
    "print(fruits[-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9263282b",
   "metadata": {},
   "source": [
    "## Эксперимент 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8658ec39",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:37.290712Z",
     "iopub.status.busy": "2026-08-14T20:55:37.290596Z",
     "iopub.status.idle": "2026-08-14T20:55:37.293274Z",
     "shell.execute_reply": "2026-08-14T20:55:37.292849Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cartesian <class 'str'>\n",
      "5 <class 'int'>\n",
      "3.14 <class 'float'>\n",
      "True <class 'bool'>\n"
     ]
    }
   ],
   "source": [
    "smeshannyj = [\"Cartesian\", 5, 3.14, True]\n",
    "for item in smeshannyj:\n",
    "    print(item, type(item))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a7ac977",
   "metadata": {},
   "source": [
    "## Типичная ошибка\n",
    "\n",
    "Индекс за пределами списка вызывает IndexError."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "213f8845",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:37.294530Z",
     "iopub.status.busy": "2026-08-14T20:55:37.294353Z",
     "iopub.status.idle": "2026-08-14T20:55:37.320288Z",
     "shell.execute_reply": "2026-08-14T20:55:37.319678Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mIndexError\u001b[39m                                Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m      1\u001b[39m fruits = [\u001b[33m\"яблоко\"\u001b[39m, \u001b[33m\"банан\"\u001b[39m, \u001b[33m\"вишня\"\u001b[39m]\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m fruits[\u001b[32m10\u001b[39m]\n",
      "\u001b[31mIndexError\u001b[39m: list index out of range"
     ]
    }
   ],
   "source": [
    "fruits = [\"яблоко\", \"банан\", \"вишня\"]\n",
    "fruits[10]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fdce25c",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Создайте список из пяти любимых чисел и выведите первое, последнее и третье с конца."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4836bebc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:37.321352Z",
     "iopub.status.busy": "2026-08-14T20:55:37.321237Z",
     "iopub.status.idle": "2026-08-14T20:55:37.323840Z",
     "shell.execute_reply": "2026-08-14T20:55:37.323312Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7 100 21\n"
     ]
    }
   ],
   "source": [
    "numbers = [7, 14, 21, 42, 100]\n",
    "print(numbers[0], numbers[-1], numbers[-3])"
   ]
  }
 ],
 "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
}
