{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 内置常量\n",
    "\n",
    "- 布尔值：{data}`False` （表示逻辑值为假）、{data}`True` （表示逻辑值为真）\n",
    "- 空值：{data}`None`\n",
    "- {data}`NotImplemented`\n",
    "- {data}`Ellipsis`：与省略号字面值 `...` 相同。\n",
    "- {data}`__debug__`\n",
    "\n",
    "名称 {data}`None`，{data}`False`，{data}`True` 和 {data}`__debug__` 无法重新赋值（赋值给它们，即使是属性名，将引发 {exc}`SyntaxError`），所以它们可以被认为是“真正的”常量。\n",
    "\n",
    "演示如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "False = 'e'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "True = 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "None  = 'w'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "__debug__ = 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## {data}`NotImplemented`\n",
    "\n",
    "{data}`NotImplemented` 是 {data}`types.NotImplementedType` 类型的唯一实例。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "NotImplementedType"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(NotImplemented)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "作为布尔值来解读 `NotImplemented` 已被弃用。虽然它目前会被解读为真值，但将同时发出 : {exc}`DeprecationWarning`。它将在未来的 Python 版本中引发 {exc}`TypeError`。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\xinzo\\AppData\\Local\\Temp/ipykernel_4936/3586968809.py:1: DeprecationWarning: NotImplemented should not be used in a boolean context\n",
      "  bool(NotImplemented)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(NotImplemented)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当二元（或就地）运算返回 `NotImplemented` 时，解释器将尝试对另一种类型（或其他一些回滚操作，取决于运算符）实施反射操作。如果所有尝试都返回 `NotImplemented`，则解释器将引发适当的异常。错误返回的 `NotImplemented` 将导致误导性错误消息或返回到 Python 代码中的 `NotImplemented` 值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from demo.a import A, B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = A(4)\n",
    "b = B(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Comparing an A with a B\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Could not compare B with the other class\n",
      "Comparing an A with a B\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b == a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "f3aa50f0c7e40bcc9cedd2a4cdb1116a2b731edfa88dfef927032477c9c99d10"
  },
  "kernelspec": {
   "display_name": "Python 3.10.0 64-bit ('hs': conda)",
   "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.10.0"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
