{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "94d81aa5",
   "metadata": {},
   "source": [
    "# 08-01 · Что такое строки?\n",
    "\n",
    "Практика к разделам [«Что такое строки?»](../../site/chapters/glava-08/08-01-chto-takoe-stroki.html) и [«Кавычки и объединение строк»](../../site/chapters/glava-08/08-02-kavychki-konkatenaciya.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f30397b",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Создавать строки, объединять их и работать с кавычками внутри текста."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d6fa7f9",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "125a79c1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:46.430204Z",
     "iopub.status.busy": "2026-08-14T20:53:46.430094Z",
     "iopub.status.idle": "2026-08-14T20:53:46.449632Z",
     "shell.execute_reply": "2026-08-14T20:53:46.449138Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет Cartesian\n"
     ]
    }
   ],
   "source": [
    "greeting = \"Привет\"\n",
    "name = \"Cartesian\"\n",
    "print(greeting, name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7e8c3de",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — многострочная строка"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0e8f107d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:46.450693Z",
     "iopub.status.busy": "2026-08-14T20:53:46.450568Z",
     "iopub.status.idle": "2026-08-14T20:53:46.452755Z",
     "shell.execute_reply": "2026-08-14T20:53:46.452388Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Код за кодом,\n",
      "шаг за шагом —\n",
      "так рождается\n",
      "программа.\n"
     ]
    }
   ],
   "source": [
    "poem = \"\"\"Код за кодом,\n",
    "шаг за шагом —\n",
    "так рождается\n",
    "программа.\"\"\"\n",
    "print(poem)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e17cd7d0",
   "metadata": {},
   "source": [
    "## Эксперимент 2 — конкатенация"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "546a422e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:46.453755Z",
     "iopub.status.busy": "2026-08-14T20:53:46.453648Z",
     "iopub.status.idle": "2026-08-14T20:53:46.455764Z",
     "shell.execute_reply": "2026-08-14T20:53:46.455470Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ада Лавлейс\n"
     ]
    }
   ],
   "source": [
    "first = \"Ада\"\n",
    "last = \"Лавлейс\"\n",
    "full = first + \" \" + last\n",
    "print(full)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbb3b679",
   "metadata": {},
   "source": [
    "## Типичная ошибка\n",
    "\n",
    "Сложение строки и числа напрямую вызывает `TypeError`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e30fb9a7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:46.456811Z",
     "iopub.status.busy": "2026-08-14T20:53:46.456707Z",
     "iopub.status.idle": "2026-08-14T20:53:46.482943Z",
     "shell.execute_reply": "2026-08-14T20:53:46.482428Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "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[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[33m\"Возраст: \"\u001b[39m + \u001b[32m10\u001b[39m\n",
      "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "\"Возраст: \" + 10"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa0182c2",
   "metadata": {},
   "source": [
    "## Исправление"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "aa9f9dae",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:46.483937Z",
     "iopub.status.busy": "2026-08-14T20:53:46.483827Z",
     "iopub.status.idle": "2026-08-14T20:53:46.486212Z",
     "shell.execute_reply": "2026-08-14T20:53:46.485767Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Возраст: 10\n",
      "Возраст: 10\n"
     ]
    }
   ],
   "source": [
    "print(\"Возраст: \" + str(10))\n",
    "print(f\"Возраст: {10}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c24e6556",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Составьте строку с кавычками внутри двумя способами — через другой тип кавычек снаружи и через экранирование."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "dd64aabb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:46.487432Z",
     "iopub.status.busy": "2026-08-14T20:53:46.487256Z",
     "iopub.status.idle": "2026-08-14T20:53:46.491295Z",
     "shell.execute_reply": "2026-08-14T20:53:46.490314Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Она сказала: 'Привет!'\n",
      "Она сказала: \"Привет!\"\n",
      "Она сказала: \"Привет!\"\n"
     ]
    }
   ],
   "source": [
    "q1 = \"Она сказала: 'Привет!'\"\n",
    "q2 = 'Она сказала: \"Привет!\"'\n",
    "q3 = \"Она сказала: \\\"Привет!\\\"\"\n",
    "print(q1)\n",
    "print(q2)\n",
    "print(q3)"
   ]
  }
 ],
 "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
}
