{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c471ed89",
   "metadata": {},
   "source": [
    "# 14-02 · Классы\n",
    "\n",
    "Практика к разделу [«Классы»](../../site/chapters/glava-14/14-02-klassy.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "123e5d0e",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Определить собственный класс и создать несколько объектов."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4344a241",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9aed6008",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:47.501865Z",
     "iopub.status.busy": "2026-08-14T20:58:47.501736Z",
     "iopub.status.idle": "2026-08-14T20:58:47.517660Z",
     "shell.execute_reply": "2026-08-14T20:58:47.517119Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Рекс 3\n"
     ]
    }
   ],
   "source": [
    "class Sobaka:\n",
    "    def __init__(self, klichka, vozrast):\n",
    "        self.klichka = klichka\n",
    "        self.vozrast = vozrast\n",
    "\n",
    "rex = Sobaka(\"Рекс\", 3)\n",
    "print(rex.klichka, rex.vozrast)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e69d838b",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — независимые объекты"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "183b04c7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:47.518637Z",
     "iopub.status.busy": "2026-08-14T20:58:47.518521Z",
     "iopub.status.idle": "2026-08-14T20:58:47.521117Z",
     "shell.execute_reply": "2026-08-14T20:58:47.520653Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Рекс 3\n",
      "Шарик 5\n"
     ]
    }
   ],
   "source": [
    "rex = Sobaka(\"Рекс\", 3)\n",
    "sharik = Sobaka(\"Шарик\", 5)\n",
    "\n",
    "print(rex.klichka, rex.vozrast)\n",
    "print(sharik.klichka, sharik.vozrast)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fccd9b0",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Создайте класс `Kniga` с атрибутами `nazvanie` и `avtor`, затем создайте три объекта."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "126300f3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:47.522069Z",
     "iopub.status.busy": "2026-08-14T20:58:47.521959Z",
     "iopub.status.idle": "2026-08-14T20:58:47.524961Z",
     "shell.execute_reply": "2026-08-14T20:58:47.524478Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Война и мир — Толстой\n",
      "Мастер и Маргарита — Булгаков\n",
      "Преступление и наказание — Достоевский\n"
     ]
    }
   ],
   "source": [
    "class Kniga:\n",
    "    def __init__(self, nazvanie, avtor):\n",
    "        self.nazvanie = nazvanie\n",
    "        self.avtor = avtor\n",
    "\n",
    "knigi = [\n",
    "    Kniga(\"Война и мир\", \"Толстой\"),\n",
    "    Kniga(\"Мастер и Маргарита\", \"Булгаков\"),\n",
    "    Kniga(\"Преступление и наказание\", \"Достоевский\"),\n",
    "]\n",
    "\n",
    "for k in knigi:\n",
    "    print(f\"{k.nazvanie} — {k.avtor}\")"
   ]
  }
 ],
 "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
}
