{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ca655ca0",
   "metadata": {},
   "source": [
    "# 08-04 · Методы строк\n",
    "\n",
    "Практика к разделу [«Методы строк»](../../site/chapters/glava-08/08-04-metody-strok.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e334517b",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить upper, lower, strip, replace, count, split и другие методы."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63d4b546",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "03e4dd8d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:48.121894Z",
     "iopub.status.busy": "2026-08-14T20:53:48.121749Z",
     "iopub.status.idle": "2026-08-14T20:53:48.141542Z",
     "shell.execute_reply": "2026-08-14T20:53:48.141078Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "PYTHON С НУЛЯ\n",
      "python с нуля\n",
      "Python С Нуля\n"
     ]
    }
   ],
   "source": [
    "text = \"Python с нуля\"\n",
    "print(text.upper())\n",
    "print(text.lower())\n",
    "print(text.title())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92601111",
   "metadata": {},
   "source": [
    "## Эксперимент 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3da3d7cf",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:48.142984Z",
     "iopub.status.busy": "2026-08-14T20:53:48.142860Z",
     "iopub.status.idle": "2026-08-14T20:53:48.145383Z",
     "shell.execute_reply": "2026-08-14T20:53:48.144990Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'Python с нуля'\n",
      "  Python с начала  \n",
      "1\n"
     ]
    }
   ],
   "source": [
    "text = \"  Python с нуля  \"\n",
    "print(repr(text.strip()))\n",
    "print(text.replace(\"нуля\", \"начала\"))\n",
    "print(text.count(\"н\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "834ba5dc",
   "metadata": {},
   "source": [
    "## Эксперимент 2 — split()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "26bfb09d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:48.146523Z",
     "iopub.status.busy": "2026-08-14T20:53:48.146414Z",
     "iopub.status.idle": "2026-08-14T20:53:48.148632Z",
     "shell.execute_reply": "2026-08-14T20:53:48.148222Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Python', 'любит', 'числа', 'и', 'буквы']\n",
      "5 слов\n"
     ]
    }
   ],
   "source": [
    "sentence = \"Python любит числа и буквы\"\n",
    "words = sentence.split()\n",
    "print(words)\n",
    "print(len(words), \"слов\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6eb2d332",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Проверьте, начинается ли и заканчивается ли слово «Cartesian» определёнными буквами."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "eadfb1e4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:48.149562Z",
     "iopub.status.busy": "2026-08-14T20:53:48.149460Z",
     "iopub.status.idle": "2026-08-14T20:53:48.151646Z",
     "shell.execute_reply": "2026-08-14T20:53:48.151284Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "word = \"Cartesian\"\n",
    "print(word.startswith(\"Car\"))\n",
    "print(word.endswith(\"an\"))\n",
    "print(word.startswith(\"art\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cfbf6f7",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "Посчитайте, сколько слов длиннее 4 букв в предложении."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f21d8234",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:48.152638Z",
     "iopub.status.busy": "2026-08-14T20:53:48.152534Z",
     "iopub.status.idle": "2026-08-14T20:53:48.154908Z",
     "shell.execute_reply": "2026-08-14T20:53:48.154479Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Длинных слов: 7\n"
     ]
    }
   ],
   "source": [
    "sentence = \"Python любит числа и красивые буквы очень сильно\"\n",
    "words = sentence.split()\n",
    "count = 0\n",
    "for w in words:\n",
    "    if len(w) > 4:\n",
    "        count += 1\n",
    "print(\"Длинных слов:\", count)"
   ]
  }
 ],
 "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
}
