{"id":43786,"date":"2025-08-04T17:54:00","date_gmt":"2025-08-04T08:54:00","guid":{"rendered":"https:\/\/techgym.jp\/?p=43786"},"modified":"2025-08-04T17:54:34","modified_gmt":"2025-08-04T08:54:34","slug":"python-is-diff","status":"publish","type":"post","link":"https:\/\/techgym.jp\/column\/python-is-diff\/","title":{"rendered":"Python ==\u6f14\u7b97\u5b50\u3068is\u6f14\u7b97\u5b50\u306e\u9055\u3044\u5b8c\u5168\u30ac\u30a4\u30c9 &#8211; \u4f7f\u3044\u5206\u3051\u3068\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9"},"content":{"rendered":"\n<p>\u00a0<\/p>\n<h2>==\u6f14\u7b97\u5b50\u3068is\u6f14\u7b97\u5b50\u3068\u306f\uff1f<\/h2>\n<p>Python \u306e <code>==<\/code> \u6f14\u7b97\u5b50\u3068 <code>is<\/code> \u6f14\u7b97\u5b50\u306f\u3001\u3069\u3061\u3089\u3082\u6bd4\u8f03\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u304c\u3001\u5168\u304f\u7570\u306a\u308b\u6982\u5ff5\u3092\u6bd4\u8f03\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u9055\u3044\u3092\u6b63\u3057\u304f\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001\u30d0\u30b0\u306e\u5c11\u306a\u3044\u52b9\u7387\u7684\u306aPython\u30b3\u30fc\u30c9\u304c\u66f8\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u57fa\u672c\u7684\u306a\u9055\u3044<\/h2>\n<h3>==\u6f14\u7b97\u5b50\uff08\u7b49\u4fa1\u6027\u306e\u6bd4\u8f03\uff09<\/h3>\n<ul>\n<li>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e<strong>\u5024<\/strong>\u304c\u7b49\u3057\u3044\u304b\u3092\u5224\u5b9a<\/li>\n<li><code>__eq__()<\/code> \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059<\/li>\n<li><strong>\u5185\u5bb9<\/strong>\u3092\u6bd4\u8f03\u3059\u308b<\/li>\n<\/ul>\n<h3>is\u6f14\u7b97\u5b50\uff08\u540c\u4e00\u6027\u306e\u6bd4\u8f03\uff09<\/h3>\n<ul>\n<li>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e<strong>\u30a2\u30a4\u30c7\u30f3\u30c6\u30a3\u30c6\u30a3<\/strong>\u304c\u540c\u3058\u304b\u3092\u5224\u5b9a<\/li>\n<li>\u30e1\u30e2\u30ea\u4e0a\u306e<strong>\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u304b\u3092\u78ba\u8a8d<\/li>\n<li><code>id()<\/code> \u95a2\u6570\u306e\u7d50\u679c\u3092\u6bd4\u8f03<\/li>\n<\/ul>\n<h2>\u57fa\u672c\u7684\u306a\u6bd4\u8f03\u4f8b<\/h2>\n<h3>1. \u6570\u5024\u3067\u306e\u6bd4\u8f03<\/h3>\n<pre><code class=\"language-python\"># \u7b49\u4fa1\u6027\u306e\u6bd4\u8f03\na = 1000\nb = 1000\nprint(a == b)  # True\uff08\u5024\u304c\u540c\u3058\uff09\nprint(a is b)  # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n\n# \u30aa\u30d6\u30b8\u30a7\u30af\u30c8ID\u3092\u78ba\u8a8d\nprint(id(a))   # 140712345678912 (\u4f8b)\nprint(id(b))   # 140712345678944 (\u4f8b\uff1a\u7570\u306a\u308bID)\n<\/code><\/pre>\n<h3>2. \u5c0f\u3055\u306a\u6574\u6570\u3067\u306e\u7279\u6b8a\u306a\u30b1\u30fc\u30b9<\/h3>\n<pre><code class=\"language-python\"># -5\u304b\u3089256\u307e\u3067\u306e\u6574\u6570\u306f\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\nx = 100\ny = 100\nprint(x == y)  # True\nprint(x is y)  # True\uff08\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n\n# \u5927\u304d\u306a\u6570\u5024\u306f\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\nx = 1000\ny = 1000\nprint(x == y)  # True\nprint(x is y)  # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n<\/code><\/pre>\n<h3>3. \u6587\u5b57\u5217\u3067\u306e\u6bd4\u8f03<\/h3>\n<pre><code class=\"language-python\"># \u77ed\u3044\u6587\u5b57\u5217\uff08\u30a4\u30f3\u30bf\u30fc\u30f3\uff09\ns1 = \"hello\"\ns2 = \"hello\"\nprint(s1 == s2)  # True\nprint(s1 is s2)  # True\uff08\u30a4\u30f3\u30bf\u30fc\u30f3\u3055\u308c\u3066\u3044\u308b\uff09\n\n# \u52d5\u7684\u306b\u4f5c\u6210\u3055\u308c\u305f\u6587\u5b57\u5217\ns3 = \"hel\" + \"lo\"\ns4 = \"hello\"\nprint(s3 == s4)  # True\nprint(s3 is s4)  # True\uff08\u6700\u9069\u5316\u306b\u3088\u308a\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n\n# \u30b9\u30da\u30fc\u30b9\u3092\u542b\u3080\u6587\u5b57\u5217\ns5 = \"hello world\"\ns6 = \"hello world\"\nprint(s5 == s6)  # True\nprint(s5 is s6)  # \u5b9f\u88c5\u4f9d\u5b58\uff08\u901a\u5e38\u306fTrue\uff09\n<\/code><\/pre>\n<h2>\u30ea\u30b9\u30c8\u3068\u8f9e\u66f8\u3067\u306e\u6bd4\u8f03<\/h2>\n<h3>1. \u30ea\u30b9\u30c8\u3067\u306e\u6bd4\u8f03<\/h3>\n<pre><code class=\"language-python\"># \u540c\u3058\u5185\u5bb9\u306e\u30ea\u30b9\u30c8\nlist1 = [1, 2, 3]\nlist2 = [1, 2, 3]\nprint(list1 == list2)  # True\uff08\u5185\u5bb9\u304c\u540c\u3058\uff09\nprint(list1 is list2)  # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n\n# \u540c\u3058\u30ea\u30b9\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\nlist3 = [1, 2, 3]\nlist4 = list3\nprint(list3 == list4)  # True\nprint(list3 is list4)  # True\uff08\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n\n# \u30ea\u30b9\u30c8\u306e\u30b3\u30d4\u30fc\nlist5 = [1, 2, 3]\nlist6 = list5.copy()\nprint(list5 == list6)  # True\uff08\u5185\u5bb9\u304c\u540c\u3058\uff09\nprint(list5 is list6)  # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n<\/code><\/pre>\n<h3>2. \u8f9e\u66f8\u3067\u306e\u6bd4\u8f03<\/h3>\n<pre><code class=\"language-python\"># \u540c\u3058\u5185\u5bb9\u306e\u8f9e\u66f8\ndict1 = {\"a\": 1, \"b\": 2}\ndict2 = {\"a\": 1, \"b\": 2}\nprint(dict1 == dict2)  # True\nprint(dict1 is dict2)  # False\n\n# \u9806\u5e8f\u304c\u7570\u306a\u308b\u304c\u5185\u5bb9\u306f\u540c\u3058\ndict3 = {\"a\": 1, \"b\": 2}\ndict4 = {\"b\": 2, \"a\": 1}\nprint(dict3 == dict4)  # True\nprint(dict3 is dict4)  # False\n<\/code><\/pre>\n<h2>None\u3001True\u3001False\u3067\u306e\u6bd4\u8f03<\/h2>\n<h3>1. None\u3068\u306e\u6bd4\u8f03\uff08\u91cd\u8981\uff09<\/h3>\n<pre><code class=\"language-python\"># \u6b63\u3057\u3044None\u5224\u5b9a\nvalue = None\nprint(value is None)  # True\uff08\u63a8\u5968\uff09\nprint(value == None)  # True\uff08\u975e\u63a8\u5968\uff09\n\n# \u30ab\u30b9\u30bf\u30e0\u30af\u30e9\u30b9\u3067\u306e\u554f\u984c\u4f8b\nclass CustomNone:\n    def __eq__(self, other):\n        return other is None\n\ncustom = CustomNone()\nprint(custom == None)   # True\uff08__eq__\u306b\u3088\u308a\uff09\nprint(custom is None)   # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n<\/code><\/pre>\n<h3>2. \u30d6\u30fc\u30eb\u5024\u3067\u306e\u6bd4\u8f03<\/h3>\n<pre><code class=\"language-python\"># \u30d6\u30fc\u30eb\u5024\u306e\u6bd4\u8f03\nflag1 = True\nflag2 = True\nprint(flag1 == flag2)  # True\nprint(flag1 is flag2)  # True\uff08\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n\n# \u8a08\u7b97\u7d50\u679c\u306e\u30d6\u30fc\u30eb\u5024\nresult1 = (5 &gt; 3)\nresult2 = True\nprint(result1 == result2)  # True\nprint(result1 is result2)  # True\n<\/code><\/pre>\n<h2>\u30ab\u30b9\u30bf\u30e0\u30af\u30e9\u30b9\u3067\u306e\u6bd4\u8f03<\/h2>\n<h3>1. __eq__\u30e1\u30bd\u30c3\u30c9\u306e\u5b9f\u88c5<\/h3>\n<pre><code class=\"language-python\">class Person:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n    \n    def __eq__(self, other):\n        if isinstance(other, Person):\n            return self.name == other.name and self.age == other.age\n        return False\n\n# \u4f7f\u7528\u4f8b\nperson1 = Person(\"\u592a\u90ce\", 25)\nperson2 = Person(\"\u592a\u90ce\", 25)\nperson3 = person1\n\nprint(person1 == person2)  # True\uff08\u540c\u3058\u540d\u524d\u3068\u5e74\u9f62\uff09\nprint(person1 is person2)  # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\nprint(person1 is person3)  # True\uff08\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n<\/code><\/pre>\n<h3>2. __eq__\u3092\u5b9f\u88c5\u3057\u306a\u3044\u30af\u30e9\u30b9<\/h3>\n<pre><code class=\"language-python\">class SimpleClass:\n    def __init__(self, value):\n        self.value = value\n\nobj1 = SimpleClass(42)\nobj2 = SimpleClass(42)\nobj3 = obj1\n\nprint(obj1 == obj2)  # False\uff08\u540c\u3058\u5024\u3060\u304c\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\nprint(obj1 is obj2)  # False\nprint(obj1 is obj3)  # True\uff08\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n<\/code><\/pre>\n<h2>\u5b9f\u8df5\u7684\u306a\u4f7f\u7528\u4f8b<\/h2>\n<h3>1. None\u5224\u5b9a\u3067\u306e\u6b63\u3057\u3044\u4f7f\u3044\u65b9<\/h3>\n<pre><code class=\"language-python\">def process_data(data=None):\n    # \u6b63\u3057\u3044\u66f8\u304d\u65b9\n    if data is None:\n        data = []\n    \n    # \u9593\u9055\u3063\u305f\u66f8\u304d\u65b9\n    # if data == None:  # \u63a8\u5968\u3055\u308c\u306a\u3044\n    \n    return len(data)\n\n# \u4f7f\u7528\u4f8b\nprint(process_data())        # 0\nprint(process_data([1, 2]))  # 2\n<\/code><\/pre>\n<h3>2. \u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u30d1\u30bf\u30fc\u30f3\u3067\u306e\u6d3b\u7528<\/h3>\n<pre><code class=\"language-python\">class Singleton:\n    _instance = None\n    \n    def __new__(cls):\n        if cls._instance is None:\n            cls._instance = super().__new__(cls)\n        return cls._instance\n\n# \u4f7f\u7528\u4f8b\ns1 = Singleton()\ns2 = Singleton()\nprint(s1 == s2)  # True\nprint(s1 is s2)  # True\uff08\u540c\u3058\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\uff09\n<\/code><\/pre>\n<h3>3. \u30ea\u30b9\u30c8\u306e\u5909\u66f4\u691c\u51fa<\/h3>\n<pre><code class=\"language-python\">def modify_list(original_list):\n    new_list = original_list.copy()\n    new_list.append(\"\u65b0\u3057\u3044\u8981\u7d20\")\n    \n    print(f\"\u5185\u5bb9\u304c\u540c\u3058: {original_list == new_list}\")  # False\n    print(f\"\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8: {original_list is new_list}\")  # False\n    \n    return new_list\n\n# \u4f7f\u7528\u4f8b\nmy_list = [1, 2, 3]\nmodified = modify_list(my_list)\n<\/code><\/pre>\n<h2>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u6bd4\u8f03<\/h2>\n<h3>1. \u901f\u5ea6\u306e\u9055\u3044<\/h3>\n<pre><code class=\"language-python\">import timeit\n\n# is\u6f14\u7b97\u5b50\u306e\u30c6\u30b9\u30c8\uff08\u9ad8\u901f\uff09\ndef test_is():\n    a = None\n    return a is None\n\n# ==\u6f14\u7b97\u5b50\u306e\u30c6\u30b9\u30c8\uff08\u76f8\u5bfe\u7684\u306b\u4f4e\u901f\uff09\ndef test_equals():\n    a = None\n    return a == None\n\n# \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6bd4\u8f03\ntime_is = timeit.timeit(test_is, number=1000000)\ntime_eq = timeit.timeit(test_equals, number=1000000)\n\nprint(f\"is\u6f14\u7b97\u5b50: {time_is:.6f}\u79d2\")\nprint(f\"==\u6f14\u7b97\u5b50: {time_eq:.6f}\u79d2\")\n<\/code><\/pre>\n<h3>2. \u5927\u304d\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u306e\u6bd4\u8f03<\/h3>\n<pre><code class=\"language-python\"># \u5927\u304d\u306a\u30ea\u30b9\u30c8\u3067\u306e\u6bd4\u8f03\nlarge_list1 = list(range(10000))\nlarge_list2 = list(range(10000))\nlarge_list3 = large_list1\n\n# ==\u306f\u5185\u5bb9\u3092\u3059\u3079\u3066\u6bd4\u8f03\uff08\u6642\u9593\u304c\u304b\u304b\u308b\uff09\nprint(large_list1 == large_list2)  # True\uff08\u9045\u3044\uff09\n\n# is\u306f\u5373\u5ea7\u306b\u5224\u5b9a\uff08\u9ad8\u901f\uff09\nprint(large_list1 is large_list2)  # False\uff08\u901f\u3044\uff09\nprint(large_list1 is large_list3)  # True\uff08\u901f\u3044\uff09\n<\/code><\/pre>\n<h2>\u3088\u304f\u3042\u308b\u9593\u9055\u3044\u3068\u5bfe\u51e6\u6cd5<\/h2>\n<h3>1. \u6587\u5b57\u5217\u6bd4\u8f03\u3067\u306e\u6df7\u4e71<\/h3>\n<pre><code class=\"language-python\"># \u6587\u5b57\u5217\u30a4\u30f3\u30bf\u30fc\u30f3\u306e\u4f8b\u5916\ndef create_string():\n    return \"hello\"\n\ns1 = create_string()\ns2 = create_string()\nprint(s1 == s2)  # True\nprint(s1 is s2)  # \u5b9f\u88c5\u4f9d\u5b58\uff08\u901a\u5e38\u306fTrue\uff09\n\n# \u78ba\u5b9f\u306b\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308b\ns3 = \"\".join([\"h\", \"e\", \"l\", \"l\", \"o\"])\ns4 = \"hello\"\nprint(s3 == s4)  # True\nprint(s3 is s4)  # False\uff08\u660e\u78ba\u306b\u7570\u306a\u308b\uff09\n<\/code><\/pre>\n<h3>2. \u53ef\u5909\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u306e\u8aa4\u89e3<\/h3>\n<pre><code class=\"language-python\">def dangerous_default(items=[]):\n    items.append(\"\u65b0\u3057\u3044\u9805\u76ee\")\n    return items\n\n# \u5371\u967a\u306a\u4f8b\nlist1 = dangerous_default()\nlist2 = dangerous_default()\n\nprint(list1 == list2)  # True\nprint(list1 is list2)  # True\uff08\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff01\uff09\n\n# \u6b63\u3057\u3044\u5b9f\u88c5\ndef safe_default(items=None):\n    if items is None:\n        items = []\n    items.append(\"\u65b0\u3057\u3044\u9805\u76ee\")\n    return items\n\nlist3 = safe_default()\nlist4 = safe_default()\nprint(list3 is list4)  # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n<\/code><\/pre>\n<h3>3. \u6570\u5024\u6bd4\u8f03\u3067\u306e\u6ce8\u610f\u70b9<\/h3>\n<pre><code class=\"language-python\"># \u6d6e\u52d5\u5c0f\u6570\u70b9\u6570\u3067\u306e\u6bd4\u8f03\na = 0.1 + 0.2\nb = 0.3\nprint(a == b)  # False\uff08\u6d6e\u52d5\u5c0f\u6570\u70b9\u306e\u7cbe\u5ea6\u554f\u984c\uff09\nprint(a is b)  # False\n\n# \u6b63\u3057\u3044\u6d6e\u52d5\u5c0f\u6570\u70b9\u6bd4\u8f03\nimport math\nprint(math.isclose(a, b))  # True\n\n# Decimal\u3092\u4f7f\u3063\u305f\u6b63\u78ba\u306a\u8a08\u7b97\nfrom decimal import Decimal\nx = Decimal('0.1') + Decimal('0.2')\ny = Decimal('0.3')\nprint(x == y)  # True\nprint(x is y)  # False\uff08\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\n<\/code><\/pre>\n<h2>\u30c7\u30d0\u30c3\u30b0\u3068\u30c6\u30b9\u30c8\u3067\u306e\u6d3b\u7528<\/h2>\n<h3>1. \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u78ba\u8a8d<\/h3>\n<pre><code class=\"language-python\">def debug_comparison(obj1, obj2):\n    print(f\"obj1: {obj1} (id: {id(obj1)})\")\n    print(f\"obj2: {obj2} (id: {id(obj2)})\")\n    print(f\"obj1 == obj2: {obj1 == obj2}\")\n    print(f\"obj1 is obj2: {obj1 is obj2}\")\n    print(f\"type(obj1): {type(obj1)}\")\n    print(f\"type(obj2): {type(obj2)}\")\n    print(\"-\" * 40)\n\n# \u4f7f\u7528\u4f8b\ndebug_comparison([1, 2], [1, 2])\ndebug_comparison(\"hello\", \"hello\")\ndebug_comparison(None, None)\n<\/code><\/pre>\n<h3>2. \u30c6\u30b9\u30c8\u3067\u306e\u4f7f\u3044\u5206\u3051<\/h3>\n<pre><code class=\"language-python\">import unittest\n\nclass TestComparisons(unittest.TestCase):\n    def test_value_equality(self):\n        # \u5024\u306e\u7b49\u4fa1\u6027\u3092\u30c6\u30b9\u30c8\n        self.assertEqual([1, 2, 3], [1, 2, 3])\n        \n    def test_object_identity(self):\n        # \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u540c\u4e00\u6027\u3092\u30c6\u30b9\u30c8\n        obj = [1, 2, 3]\n        self.assertIs(obj, obj)\n        \n    def test_none_check(self):\n        # None\u5224\u5b9a\u306e\u30c6\u30b9\u30c8\n        value = None\n        self.assertIsNone(value)  # is None \u3068\u540c\u7b49\n        \n    def test_not_same_object(self):\n        # \u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308b\u3053\u3068\u3092\u30c6\u30b9\u30c8\n        list1 = [1, 2, 3]\n        list2 = [1, 2, 3]\n        self.assertEqual(list1, list2)  # \u5024\u306f\u540c\u3058\n        self.assertIsNot(list1, list2)  # \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u7570\u306a\u308b\n<\/code><\/pre>\n<h2>\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h2>\n<h3>1. \u4f7f\u3044\u5206\u3051\u306e\u6307\u91dd<\/h3>\n<pre><code class=\"language-python\"># None\u5224\u5b9a\u306f\u5e38\u306bis\u3092\u4f7f\u7528\ndef check_none(value):\n    return value is None  # \u63a8\u5968\n\n# \u30d6\u30fc\u30eb\u5024\u5224\u5b9a\u3082is\u3092\u4f7f\u7528\u53ef\u80fd\ndef check_boolean(flag):\n    return flag is True  # \u307e\u305f\u306f\u5358\u306b bool(flag)\n\n# \u5024\u306e\u6bd4\u8f03\u306b\u306f==\u3092\u4f7f\u7528\ndef check_equality(a, b):\n    return a == b  # \u63a8\u5968\n\n# \u30ea\u30b9\u30c8\u3084\u8f9e\u66f8\u306e\u540c\u4e00\u6027\u78ba\u8a8d\u306b\u306fis\u3092\u4f7f\u7528\ndef are_same_list(list1, list2):\n    return list1 is list2\n<\/code><\/pre>\n<h3>2. \u578b\u30c1\u30a7\u30c3\u30af\u3068\u306e\u7d44\u307f\u5408\u308f\u305b<\/h3>\n<pre><code class=\"language-python\">def safe_comparison(obj1, obj2):\n    # \u578b\u30c1\u30a7\u30c3\u30af\n    if type(obj1) != type(obj2):\n        return False\n    \n    # None\u5224\u5b9a\n    if obj1 is None and obj2 is None:\n        return True\n    \n    # \u5024\u306e\u6bd4\u8f03\n    return obj1 == obj2\n\n# \u4f7f\u7528\u4f8b\nprint(safe_comparison(None, None))    # True\nprint(safe_comparison([1, 2], [1, 2]))  # True\nprint(safe_comparison(\"hello\", 42))   # False\n<\/code><\/pre>\n<h2>\u307e\u3068\u3081<\/h2>\n<p><code>==<\/code> \u6f14\u7b97\u5b50\u3068 <code>is<\/code> \u6f14\u7b97\u5b50\u306e\u9069\u5207\u306a\u4f7f\u3044\u5206\u3051\uff1a<\/p>\n<h3>==\u6f14\u7b97\u5b50\u3092\u4f7f\u3046\u5834\u9762<\/h3>\n<ul>\n<li><strong>\u5024\u306e\u7b49\u4fa1\u6027<\/strong>\u3092\u78ba\u8a8d\u3057\u305f\u3044<\/li>\n<li><strong>\u30ea\u30b9\u30c8\u3084\u8f9e\u66f8\u306e\u5185\u5bb9<\/strong>\u3092\u6bd4\u8f03\u3057\u305f\u3044<\/li>\n<li><strong>\u30ab\u30b9\u30bf\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306e\u8ad6\u7406\u7684\u306a\u7b49\u4fa1\u6027\u3092\u5224\u5b9a\u3057\u305f\u3044<\/li>\n<\/ul>\n<h3>is\u6f14\u7b97\u5b50\u3092\u4f7f\u3046\u5834\u9762<\/h3>\n<ul>\n<li><strong>None\u5224\u5b9a<\/strong>\uff08\u6700\u3082\u91cd\u8981\uff09<\/li>\n<li><strong>True\/False<\/strong>\u3068\u306e\u76f4\u63a5\u6bd4\u8f03<\/li>\n<li><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u540c\u4e00\u6027<\/strong>\u3092\u78ba\u8a8d\u3057\u305f\u3044<\/li>\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9<\/strong>\u304c\u91cd\u8981\u306a\u5834\u9762<\/li>\n<\/ul>\n<p>\u6b63\u3057\u3044\u4f7f\u3044\u5206\u3051\u306b\u3088\u308a\u3001\u4e88\u671f\u3057\u306a\u3044\u30d0\u30b0\u3092\u9632\u304e\u3001\u52b9\u7387\u7684\u3067\u8aad\u307f\u3084\u3059\u3044Python\u30b3\u30fc\u30c9\u304c\u66f8\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u25a0\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"HdL8inG1EU\"><a href=\"https:\/\/techgym.jp\/column\/ori-app\/\">\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/column\/ori-app\/embed\/#?secret=VxxANf2aX1#?secret=HdL8inG1EU\" data-secret=\"HdL8inG1EU\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u25a0AI\u6642\u4ee3\u306e\u7b2c\u4e00\u6b69\uff01\u300cAI\u99c6\u52d5\u958b\u767a\u30b3\u30fc\u30b9\u300d\u306f\u3058\u3081\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<p>\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821\u3067\u5148\u884c\u958b\u59cb\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"gsXtWrpTop\"><a href=\"https:\/\/techgym.jp\/about\/ai-driven-development\/\">AI\u99c6\u52d5\u958b\u767a\/\u751f\u6210AI\u30a8\u30f3\u30b8\u30cb\u30a2\u30b3\u30fc\u30b9\uff08\u521d\u5fc3\u8005\u5411\u3051\uff09<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;AI\u99c6\u52d5\u958b\u767a\/\u751f\u6210AI\u30a8\u30f3\u30b8\u30cb\u30a2\u30b3\u30fc\u30b9\uff08\u521d\u5fc3\u8005\u5411\u3051\uff09&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/about\/ai-driven-development\/embed\/#?secret=vYkfbFVADo#?secret=gsXtWrpTop\" data-secret=\"gsXtWrpTop\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u25a0\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821<\/p>\n\n\n\n<p>\u300c\u6b66\u7530\u587e\u300d\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7248\u3068\u3044\u3048\u3070\u300c\u30c6\u30c3\u30af\u30b8\u30e0\u300d\u3002<br>\u8b1b\u7fa9\u52d5\u753b\u306a\u3057\u3001\u6559\u79d1\u66f8\u306a\u3057\u3002\u300c\u9032\u6357\u7ba1\u7406\u3068\u30b3\u30fc\u30c1\u30f3\u30b0\u300d\u3067\u52b9\u7387\u5b66\u7fd2\u3002<br>\u3088\u308a\u65e9\u304f\u3001\u3088\u308a\u5b89\u304f\u3001\u3057\u304b\u3082\u5bfe\u9762\u578b\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\u3067\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"h3Pq3HApwJ\"><a href=\"https:\/\/techgym.jp\/tokyo\/tokyo_honko\/\">\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/tokyo\/tokyo_honko\/embed\/#?secret=OKQ939lnxw#?secret=h3Pq3HApwJ\" data-secret=\"h3Pq3HApwJ\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u77ed\u671f\u8b1b\u7fd2\uff1e5\u65e5\u30675\u4e07\u5186\u306e\u300cPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u958b\u50ac\u4e2d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"plIVi4PGwn\"><a href=\"https:\/\/techgym.jp\/event\/nagatacho_camp\/\">\u72ec\u5b66\u3082\u30aa\u30f3\u30e9\u30a4\u30f3\u3082\u7121\u7406\u3060\u304b\u3089\u3001\u6709\u7d66\u3068\u3063\u3066\u300cPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u3078\u30105\u65e5\u9593\u30675\u4e07\u5186\u3011<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u72ec\u5b66\u3082\u30aa\u30f3\u30e9\u30a4\u30f3\u3082\u7121\u7406\u3060\u304b\u3089\u3001\u6709\u7d66\u3068\u3063\u3066\u300cPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u3078\u30105\u65e5\u9593\u30675\u4e07\u5186\u3011&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/event\/nagatacho_camp\/embed\/#?secret=gp2e4RSlSl#?secret=plIVi4PGwn\" data-secret=\"plIVi4PGwn\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u67081\u958b\u50ac\uff1e\u653e\u9001\u4f5c\u5bb6\u306b\u3088\u308b\u6620\u50cf\u30c7\u30a3\u30ec\u30af\u30bf\u30fc\u990a\u6210\u8b1b\u5ea7<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"hXDzyFJOzf\"><a href=\"https:\/\/techgym.jp\/event\/video_director\/\">\u73fe\u5f79\u653e\u9001\u4f5c\u5bb6\u304c\u6559\u3048\u308b\u52d5\u753b\u8b1b\u5ea7\uff01\u300e\uff24\uff2f\uff27\uff21\u300f<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u73fe\u5f79\u653e\u9001\u4f5c\u5bb6\u304c\u6559\u3048\u308b\u52d5\u753b\u8b1b\u5ea7\uff01\u300e\uff24\uff2f\uff27\uff21\u300f&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/event\/video_director\/embed\/#?secret=oL8p6Mors6#?secret=hXDzyFJOzf\" data-secret=\"hXDzyFJOzf\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u30aa\u30f3\u30e9\u30a4\u30f3\u7121\u6599\uff1e\u30bc\u30ed\u304b\u3089\u59cb\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"7u1Wmxpkmu\"><a href=\"https:\/\/techgym.jp\/tokyo_python\/\">\u30bc\u30ed\u304b\u3089\u59cb\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7\uff08\u7406\u7cfb\u30fb\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u521d\u5fc3\u8005\u5411\u3051\uff09<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30bc\u30ed\u304b\u3089\u59cb\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7\uff08\u7406\u7cfb\u30fb\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u521d\u5fc3\u8005\u5411\u3051\uff09&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/tokyo_python\/embed\/#?secret=dJPBdxwrGJ#?secret=7u1Wmxpkmu\" data-secret=\"7u1Wmxpkmu\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 ==\u6f14\u7b97\u5b50\u3068is\u6f14\u7b97\u5b50\u3068\u306f\uff1f Python \u306e == \u6f14\u7b97\u5b50\u3068 is \u6f14\u7b97\u5b50\u306f\u3001\u3069\u3061\u3089\u3082\u6bd4\u8f03\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u304c\u3001\u5168\u304f\u7570\u306a\u308b\u6982\u5ff5\u3092\u6bd4\u8f03\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u9055\u3044\u3092\u6b63\u3057\u304f\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001\u30d0\u30b0\u306e\u5c11\u306a\u3044\u52b9\u7387\u7684\u306aPython\u30b3\u30fc\u30c9\u304c\u66f8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":42501,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-43786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-column"],"views":43,"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/07\/f3403acf5c65aedec0dba821c4c26404.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts\/43786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/comments?post=43786"}],"version-history":[{"count":0,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts\/43786\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/media\/42501"}],"wp:attachment":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/media?parent=43786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/categories?post=43786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/tags?post=43786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}