{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6640f70d",
   "metadata": {},
   "source": [
    "# Wykład 6 - Napisy i pliki tekstowe, cz. 1 (napisy)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b3a2d69",
   "metadata": {},
   "source": [
    "## Napisy"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24073925",
   "metadata": {},
   "source": [
    "Napisy i obsługa pliki tekstowych, głównie sposobami natywnymi (+ trochę numpy/csv)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2456936e",
   "metadata": {},
   "source": [
    "Tworzenie napisów, podstawowe operacje:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a3aee3c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcde'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"abcde\"\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "09be113a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'aaaaaaaaaa'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"a\" * 10\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a6602a0",
   "metadata": {},
   "source": [
    "Indeksowanie + slicing podobnie jak dla list:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a1b3f8bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = \"abcdefgh\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a771a0cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'b'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8270ffd5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'bcde'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[1:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5ebe55c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ceg'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[2:7:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "860a9a77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hgfedcba'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[::-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8327941",
   "metadata": {},
   "source": [
    "Napisy są niezmienialne!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9d01393c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# s[1] = \"a\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8169923a",
   "metadata": {},
   "source": [
    "Apostrof/cudzysłów w napisach:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c05743ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"abcde'fgh\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcde'fgh\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "92e47a9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcde\"fgh'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abcde\"fgh'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "787d4ec9",
   "metadata": {},
   "source": [
    "A `\"` i `'` jednocześnie?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4fab5721",
   "metadata": {},
   "source": [
    "### Symbole ucieczki"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82f15f30",
   "metadata": {},
   "source": [
    "Wstawianie specjalnych znaków: symbool ucieczki `\\`.\n",
    "\n",
    "Fragment napisu `\\...` (gdzie ... to ciąg znaków), jest interpretowany jako pojedynczy symbol/znak specjalny."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5c7f9d8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'acde\"fghi'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"acde\\\"fghi\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "03c76e80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "acde\"fghi\n"
     ]
    }
   ],
   "source": [
    "print(\"acde\\\"fghi\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7f6f7879",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"acde'fghi\""
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"acde\\'fghi\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "04c36515",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "acde'fghi\n"
     ]
    }
   ],
   "source": [
    "print(\"acde\\'fghi\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "340c8570",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'acde\"\\'\"\"fghi'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"acde\\\"\\'\\\"\\\"fghi\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "24bba5eb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "acde\"'\"\"fghi\n"
     ]
    }
   ],
   "source": [
    "print(\"acde\\\"\\'\\\"\\\"fghi\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df94e410",
   "metadata": {},
   "source": [
    "Inne symbole: koniec linii (`\\n`), tab (`\\t`), `\\` (`\\\\`):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "77ac3af1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abc\\ndef'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abc\\ndef'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5297ca7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc\n",
      "def\n"
     ]
    }
   ],
   "source": [
    "print('abc\\ndef')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d550775d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abc\\tdef'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abc\\tdef'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "6b5e4517",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc\tdef\n"
     ]
    }
   ],
   "source": [
    "print('abc\\tdef')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "fc92cdfb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abc\\\\def'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abc\\\\def'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "71b68243",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc\\def\n"
     ]
    }
   ],
   "source": [
    "print('abc\\\\def')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa2629f4",
   "metadata": {},
   "source": [
    "### Unicode"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a2194a9",
   "metadata": {},
   "source": [
    "Unicode - międzynarodowy standard kodowania symboli (\"wszystkich\" alfabetów i kwazialfabetów, np. symboli drogowych, emojis). Obejmuje ~150000 znaków (stan na 2026 r.)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0c954b8",
   "metadata": {},
   "source": [
    "* [home.unicode.org](https://home.unicode.org)\n",
    "* [Strony kodowe](https://www.unicode.org/charts/) (np. [alfabet grecki](https://www.unicode.org/charts/PDF/U0370.pdf), [emotikony](https://www.unicode.org/charts/PDF/U1F600.pdf), [operatory matematyczne](https://www.unicode.org/charts/PDF/U2200.pdf))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "863000f5",
   "metadata": {},
   "source": [
    "Każdy symbol ma przypisaną liczbę - punkt kodowy (zazwyczaj pisaną w systemie heksadecymalnym, tj. szesnastkowym). Napisy w Pythonie mogą składać się z dowolnych symboli Unicode (wewnętrznie napis to ciąg punktów kodowych). Podobnie wyglądają napisy w wielu współczesnych językach programowania."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "291bb702",
   "metadata": {},
   "source": [
    "Wstawianie symboli Unicode do napisów: `\\xXX`, `\\uXXXX` lub `\\UXXXXXXXX` (gdzie `X` to cyfra heksadecymalna). Przykłady:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd44478b",
   "metadata": {},
   "source": [
    "* Dwie cyfry (jeden bajt):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "52cd949a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'A'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\x41'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "2454fdb1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'B'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\x42'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a8470db6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ABC'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'A\\x42C'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "61fcd1b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'α'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u03b1' # alfa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8d95b6b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'α'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'α'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "b8be3bbd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'β'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u03b2' # beta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "579529c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'αβxyz'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u03b1\\u03b2xyz' # beta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "1e6fa03e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "αβxyz\n"
     ]
    }
   ],
   "source": [
    "print('\\u03b1\\u03b2xyz')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ed58e56",
   "metadata": {},
   "source": [
    "* Cztery cyfry (dwa bajty):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "92ec90cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'∀'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u2200' # for all (kwantyfikator ogólny)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "338be693",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'∃'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u2203' # exists (kwantyfikator szczególny)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "bdbca6fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'攀'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u6500' # \"wspinać się\" (?) [uproszczony chiński]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "2516fb9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'攁'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u6501'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "0de68796",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'攂'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u6502'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3eb4a44f",
   "metadata": {},
   "source": [
    "Inne symbole:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "68d42984",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'☣'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u2623'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "5b355aaa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'☢'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u2622'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "d0ca6b9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'☡'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u2621'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "b74428d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'☠'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u2620'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "e576669a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'፼'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u137C' # \"ETHIOPIC NUMBER TEN THOUSAND\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa829177",
   "metadata": {},
   "source": [
    "* Osiem cyfr (cztery bajty):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "9bf71456",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'😀'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\U0001f600'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "6c2502e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Napis 😀\n"
     ]
    }
   ],
   "source": [
    "print('Napis \\U0001f600')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "f3920b71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'🫠🫡🫢🫣'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\U0001fae0\\U0001fae1\\U0001fae2\\U0001fae3'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bdeb734",
   "metadata": {},
   "source": [
    "Niektóre fonty nie mają wszystkich glifów (obrazów odpowiadających punktom kodowym):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "6986a08b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ᜀ'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u1700' # \"TAGALOG LETTER A\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12a46a32",
   "metadata": {},
   "source": [
    "### Dalsze konstrukcje napisów"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8f15f17",
   "metadata": {},
   "source": [
    "Surowy napis: `r\"...\"` (por. `f\"...\"`). Przydatne dla ścieżek, wyrażeń regularnych, ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "a9fd2252",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcde\\\\\\\\a\\\\xyz\\\\u2200'"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r'abcde\\\\a\\xyz\\u2200'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "93c7ea3a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abcde\\\\a\\xyz\\u2200\n"
     ]
    }
   ],
   "source": [
    "print(r'abcde\\\\a\\xyz\\u2200')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c8dc6bb",
   "metadata": {},
   "source": [
    "Napis w wielu linijkach:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "7f265f67",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abcdefghi\n"
     ]
    }
   ],
   "source": [
    "s = (\"abc\"\n",
    "     \"def\"\n",
    "     \"ghi\")\n",
    "\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b10877b",
   "metadata": {},
   "source": [
    "Potrójny `\"\"\"` (lub `'''`) - napisy wielolinijkowe:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "09227d36",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = \"\"\"Jestm napisem\n",
    "który ciągnie się\n",
    "na kilka\n",
    "linijek.\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "af29a58c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jestm napisem\\nktóry ciągnie się\\nna kilka\\nlinijek.'"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "22dc7b32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jestm napisem\n",
      "który ciągnie się\n",
      "na kilka\n",
      "linijek.\n"
     ]
    }
   ],
   "source": [
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67ee8620",
   "metadata": {},
   "source": [
    "Specjalne znaczenie takich napisów: komentarze, w szczególności docstringi ($\\rightarrow$ PyCharm)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfeb979f",
   "metadata": {},
   "source": [
    "## Metody napisów (wybrane)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f801014d",
   "metadata": {},
   "source": [
    "Przypomnienie: napisy są niezmienialne. Metody napisów mogą jednak zwracać nowe napisy."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5578fce6",
   "metadata": {},
   "source": [
    "Metody postaci `isX()` - `False` gdy napis jest pusty, `True` gdy każdy znak spełnia warunek (z pewnymi wyjątkami, np. `istitle()`)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af0e4c97",
   "metadata": {},
   "source": [
    "`isupper()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "48794505",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abc'.isupper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "0c320a87",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abC'.isupper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "76445ede",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'ABC'.isupper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "93d02e55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "''.isupper()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e399621",
   "metadata": {},
   "source": [
    "`islower()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "974e20c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abc'.islower()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "4f8f2cdf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u03b1'.islower() # mała alfa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "af035591",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(False, False)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u2200'.islower(), '\\u2200'.isupper() # kwantyfikator"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aae873d6",
   "metadata": {},
   "source": [
    "`isalpha()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "7e38ae8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'abc'.isalpha()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "3476050f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'ąć'.isalpha()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "41c900f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'αĆ'.isalpha()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "817c7e97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'αĆ123'.isalpha()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f62df235",
   "metadata": {},
   "source": [
    "`isdecimal()`, `isdigit()`, `isnumeric()` - cyfra dziesiętna, cyfra, numerał"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "95dd8cee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'1234'.isdecimal()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "d4754a58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'1234❸'.isdecimal()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "4f338679",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'1234❸'.isdigit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bfe6be9",
   "metadata": {},
   "source": [
    "Ogólnie: `isdecimal()` $\\implies$ `isdigit()` $\\implies$ `isnumeric()`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4dbf714",
   "metadata": {},
   "source": [
    "To, czy dla znaku spełnione jest \"bycie cyfrą\" etc. jest zdefiniowane w Unicode."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "9dbad9e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  char   isdecimal?   isdigit?   isnumeric? \n",
      "   1         1           1           1      \n",
      "   2         1           1           1      \n",
      "   १         1           1           1      \n",
      "   २         1           1           1      \n",
      "   ३         1           1           1      \n",
      "   ४         1           1           1      \n",
      "   ⓿         0           1           1      \n",
      "   ❶         0           1           1      \n",
      "   ❷         0           1           1      \n",
      "   ❸         0           1           1      \n",
      "   ¾         0           0           1      \n",
      "   ⅖         0           0           1      \n",
      "   ⅗         0           0           1      \n",
      "   ⅘         0           0           1      \n",
      "   ⒑         0           0           1      \n",
      "   ⒒         0           0           1      \n",
      "   ፼         0           0           1      \n"
     ]
    }
   ],
   "source": [
    "s = \"12१२३४⓿❶❷❸¾⅖⅗⅘⒑⒒፼\"\n",
    "\n",
    "print(f'{\"char\":^8}{\"isdecimal?\":^12}{\"isdigit?\":^12}{\"isnumeric?\":^12}')\n",
    "for c in s:\n",
    "    print(f'{c:^8}{c.isdecimal():^12}{c.isdigit():^12}{c.isnumeric():^12}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28df9633",
   "metadata": {},
   "source": [
    "`isalnum()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "11908488",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcDEαĆ፼\".isalnum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "8c4c7f8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcDEαĆ፼\\n\".isalnum()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd118c5f",
   "metadata": {},
   "source": [
    "`isspace()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "614a47cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"   \".isspace()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "97e65401",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"   \\n\\n\\t\\t \".isspace()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "66063ba5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"x\".isspace()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "1a82679b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\".isspace()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "a956df81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\ns = \"\"\\nwhile not s.isalnum():\\n    s = input(\"> \")\\nprint(s)\\n'"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "s = \"\"\n",
    "while not s.isalnum():\n",
    "    s = input(\"> \")\n",
    "print(s)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46a09204",
   "metadata": {},
   "source": [
    "`startswith()`, `endswith()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "5b093bdd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".startswith(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "28d84c24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".startswith(\"abc\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "82701add",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".startswith((\"ab\", \"xy\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "f71d9fc9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"xycdeFGHI\".startswith((\"ab\", \"xy\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "5ead407f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".startswith(\"cd\", 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "0ae70541",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".startswith(\"cd\", 2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "3dc703d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".endswith(\"GHI\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "61627d69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".endswith((\"GHI\", \"X\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "5aa6d07e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdeFGHI\".endswith((\"GH\", \"X\"), 0, -1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04c5f3c7",
   "metadata": {},
   "source": [
    "`count()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "60c6bd47",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".count(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "68eb0772",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".count(\"ma\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "8eb18e06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".count(\"a\", 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "4c5eea64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".count(\"a\", 5, 7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "e56f4564",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"aaaaa\".count(\"aa\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55bc78fa",
   "metadata": {},
   "source": [
    "`find()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "f937948f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".find(\"Ala\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "173ee2fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".find(\"x\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "b5deb7e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".find(\"ma\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "2334acd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".find(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "d1d8a668",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".find(\"a\", 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "5f4ed72a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".find(\"a\", 3, 5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "790ac7b3",
   "metadata": {},
   "source": [
    "`index()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "4aa74537",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".index(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "d89fd9f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# \"Ala ma kota\".index(\"a\", 3, 5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e64b1bb5",
   "metadata": {},
   "source": [
    "### `join()`, `split()`, `partition()`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75ae9931",
   "metadata": {},
   "source": [
    "`join()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "a88bbd4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Ala ma kota'"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "separator = \" \"\n",
    "strs = [\"Ala\", \"ma\", \"kota\"]\n",
    "separator.join(strs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "7fbe925a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Ala ma kota'"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\" \".join([\"Ala\", \"ma\", \"kota\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "435b11bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Ala---ma---kota'"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"---\".join((\"Ala\", \"ma\", \"kota\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00cbd7a3",
   "metadata": {},
   "source": [
    "`split()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "296f4769",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ala', 'ma', 'kota']"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".split()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "d1dc04cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ala', 'ma', 'kota']"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala    ma \\t\\t\\n kota\".split()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "47f20043",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Al', ' m', ' kot', '']"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".split(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "dadc6d8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ala ', ' kota']"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".split(\"ma\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "055dd826",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Al', ' m', ' kota']"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".split(\"a\", maxsplit=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98589307",
   "metadata": {},
   "source": [
    "`partition()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "78e705a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('Ala ', 'ma', ' kota')"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".partition(\"ma\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "4849063a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('Al', 'a', ' ma kota')"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".partition(\"a\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b495a35",
   "metadata": {},
   "source": [
    "### \"Prawostronne\" wersje"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "93f19a8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".rfind(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "2073e7f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('Ala ma kot', 'a', '')"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".rpartition(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "924de977",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ala m', ' kot', '']"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".rsplit(\"a\", maxsplit=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1e49481",
   "metadata": {},
   "source": [
    "(podobnie niektóre inne)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19bb5895",
   "metadata": {},
   "source": [
    "### Formatowanie"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a4930c9",
   "metadata": {},
   "source": [
    "`upper()`, `lower()`, `casefold()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "04860fb2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ABCDEFG'"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdEFG\".upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "991d6aea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcdefg'"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abcdEFG\".lower()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "2588fd13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Α'"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"α\".upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "86a16ce1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"α\".upper() == \"a\".upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "8535ed00",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"α\".upper().isupper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "c6499714",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SS\n",
      "ß\n",
      "ss\n"
     ]
    }
   ],
   "source": [
    "s = \"ß\"\n",
    "print(s.upper())\n",
    "print(s.lower())\n",
    "print(s.casefold())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86821682",
   "metadata": {},
   "source": [
    "`casefold()` jest przydatny przy porównywaniu tych samych słów z alternatywną pisownią znaków:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "d879485b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"groß\".lower() == \"gross\".lower()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "afbfb683",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"groß\".casefold() == \"gross\".casefold()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5820f8a",
   "metadata": {},
   "source": [
    "Podobny przykład: σ i ς - dwie małe litery sigma."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a9c0be5",
   "metadata": {},
   "source": [
    "`ljust()`, `rjust()`, `center()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "e9e0cf10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abc       '"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abc\".ljust(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "a7b1bc08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'       abc'"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abc\".rjust(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "d7949902",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'   abc    '"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abc\".center(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "e9b03f2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'XXXabcXXXX'"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abc\".center(10, \"X\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "392052cc",
   "metadata": {},
   "source": [
    "`strip()`, `lstrip()`, `rstrip()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "e39e52fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = \"aaabbbaXaaYaaZabbbaaa\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "24e9c5d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'bbbaXaaYaaZabbb'"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.strip(\"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "41753b46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'XaaYaaZ'"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.strip(\"ab\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "2648faff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'XaaYaaZabbbaaa'"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.lstrip(\"ab\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "a9c9844f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'aaabbbaXaaYaaZ'"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.rstrip(\"ab\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "71cd2b7c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcdefg'"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"   \\t \\n abcdefg   \\t\".strip()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d18cd218",
   "metadata": {},
   "source": [
    "`replace()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "aa07c907",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Adam ma kota'"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".replace(\"Ala\", \"Adam\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "b172a27b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alf mf kotf'"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Ala ma kota\".replace(\"a\", \"f\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "be17bb8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'XXa'"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"aaaaa\".replace(\"aa\", \"X\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c75a90f9",
   "metadata": {},
   "source": [
    "`format()` - podobno jak dla f-stringów."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "a9af8074",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'XXXXXXXXXXXXXXXXXzzz'"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{:X>20}\".format('zzz')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "7545f8c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'xyx'"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{0}{1}{0}\".format('x', 'y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "d98cc568",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'13 2 END'"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{x} {l[1]} {0}\".format(\"END\", l=[1,2], x=13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "c5975074",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Y X\n",
      "X Y\n",
      "X Y X\n"
     ]
    }
   ],
   "source": [
    "lst = [\"{} X\", \"X {}\", \"X {} X\"]\n",
    "for s in lst:\n",
    "    print(s.format(\"Y\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7f66e80",
   "metadata": {},
   "source": [
    "Obsługa plików $\\rightarrow$ PyCharm."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "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.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
