{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8d0a10e2",
   "metadata": {},
   "source": [
    "# 09-01 · Истина или ложь\n",
    "\n",
    "Практика к разделу [«Истина или ложь»](../../site/chapters/glava-09/09-01-istina-ili-lozh.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2177763f",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить тип bool и истинность значений разных типов."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "947ac3f4",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1f68c10a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:52.339423Z",
     "iopub.status.busy": "2026-08-14T20:53:52.339307Z",
     "iopub.status.idle": "2026-08-14T20:53:52.361723Z",
     "shell.execute_reply": "2026-08-14T20:53:52.361206Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True <class 'bool'>\n"
     ]
    }
   ],
   "source": [
    "is_sunny = True\n",
    "print(is_sunny, type(is_sunny))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca4ec53c",
   "metadata": {},
   "source": [
    "## Эксперимент 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dd99b462",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:52.362707Z",
     "iopub.status.busy": "2026-08-14T20:53:52.362595Z",
     "iopub.status.idle": "2026-08-14T20:53:52.364995Z",
     "shell.execute_reply": "2026-08-14T20:53:52.364507Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print(bool(0))\n",
    "print(bool(42))\n",
    "print(bool(\"\"))\n",
    "print(bool(\"нет\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3650af39",
   "metadata": {},
   "source": [
    "## Эксперимент 2 — неожиданный случай"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "eaabf468",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:52.365919Z",
     "iopub.status.busy": "2026-08-14T20:53:52.365795Z",
     "iopub.status.idle": "2026-08-14T20:53:52.368189Z",
     "shell.execute_reply": "2026-08-14T20:53:52.367572Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "print(bool(\"False\"))   # True! строка непустая, значит \"истина\"\n",
    "print(bool([]))        # пустой список — тоже \"ложь\", забегаем немного вперёд (глава 11)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a29a0b62",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Проверьте истинность пяти разных значений на свой выбор — включая хотя бы одно, для которого результат неочевиден заранее."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ce4e18bb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:52.369468Z",
     "iopub.status.busy": "2026-08-14T20:53:52.369287Z",
     "iopub.status.idle": "2026-08-14T20:53:52.371912Z",
     "shell.execute_reply": "2026-08-14T20:53:52.371492Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 -> False\n",
      "1 -> True\n",
      "-1 -> True\n",
      "'' -> False\n",
      "' ' -> True\n",
      "'0' -> True\n"
     ]
    }
   ],
   "source": [
    "for value in [0, 1, -1, \"\", \" \", \"0\"]:\n",
    "    print(repr(value), \"->\", bool(value))"
   ]
  }
 ],
 "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
}
