{"id":178910,"date":"2024-05-08T20:01:35","date_gmt":"2024-05-08T12:01:35","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/178910.html"},"modified":"2024-05-08T20:02:15","modified_gmt":"2024-05-08T12:02:15","slug":"python%e4%b8%adis%e8%bf%90%e7%ae%97%e7%ac%a6%e6%af%94%e8%be%83%e7%9a%84%e5%88%b0%e5%ba%95%e6%98%af%e4%bb%80%e4%b9%88%e5%86%85%e5%ae%b9-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/178910.html","title":{"rendered":"Python\u4e2d\u201cis\u201d\u8fd0\u7b97\u7b26\u6bd4\u8f83\u7684\u5230\u5e95\u662f\u4ec0\u4e48\u5185\u5bb9"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27063601\/9e27313c-c462-469a-a544-a2619f7c9376.webp\" alt=\"Python\u4e2d\u201cis\u201d\u8fd0\u7b97\u7b26\u6bd4\u8f83\u7684\u5230\u5e95\u662f\u4ec0\u4e48\u5185\u5bb9\" \/><\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u201cis\u201d\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684<strong>\u6807\u8bc6\uff08identity\uff09<\/strong>\uff0c\u800c\u4e0d\u662f\u5b83\u4eec\u7684\u503c\u3002\u5f53\u6211\u4eec\u4f7f\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\u65f6\uff0cPython\u4f1a\u68c0\u67e5\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u5177\u6709\u76f8\u540c\u7684\u6807\u8bc6\u2014\u2014\u5373\uff0c\u5b83\u4eec\u662f\u5426\u6307\u5411\u5185\u5b58\u4e2d\u7684\u540c\u4e00\u4f4d\u7f6e\u3002\u8fd9\u4e0e\u201c==\u201d\u8fd0\u7b97\u7b26\u4e0d\u540c\uff0c\u540e\u8005\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002<strong>\u201cis\u201d\u8fd0\u7b97\u7b26\u7684\u4e3b\u8981\u5e94\u7528\u573a\u666f\u662f\u6bd4\u8f83\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3aNone<\/strong>\uff0c\u6216\u8005\u7528\u4e8e\u786e\u4fdd\u4e24\u4e2a\u53d8\u91cf\u786e\u5b9e\u5f15\u7528\u4e86\u5185\u5b58\u4e2d\u7684\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u5185\u5bb9\u76f8\u540c\u7684\u4e24\u4e2a\u4e0d\u540c\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u7406\u89e3\u5bf9\u8c61\u6807\u8bc6\u548c\u503c\u7684\u533a\u522b<\/h3>\n<\/p>\n<p><p>\u5728\u6df1\u5165\u7406\u89e3\u201cis\u201d\u8fd0\u7b97\u7b26\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u533a\u5206\u4e24\u4e2a\u57fa\u672c\u6982\u5ff5\uff1a\u5bf9\u8c61\u7684\u201c\u6807\u8bc6(identity)\u201d\u548c\u5bf9\u8c61\u7684\u201c\u503c(value)\u201d\u3002\u5bf9\u8c61\u7684\u6807\u8bc6\u662fPython\u5206\u914d\u7ed9\u6bcf\u4e2a\u5bf9\u8c61\u7684\u552f\u4e00\u6807\u8bb0\uff0c\u53ef\u4ee5\u901a\u8fc7<code>id()<\/code>\u51fd\u6570\u83b7\u53d6\u3002\u800c\u5bf9\u8c61\u7684\u503c\u662f\u5bf9\u8c61\u5b58\u50a8\u7684\u6570\u636e\u672c\u8eab\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5e94\u7528\u573a\u666f\u548c\u91cd\u8981\u6027<\/h3>\n<\/p>\n<p><p>\u201cis\u201d\u8fd0\u7b97\u7b26\u6700\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u662f\u5224\u65ad\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3aNone\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u201cis None\u201d\u901a\u5e38\u6bd4\u201c== None\u201d\u66f4\u63a8\u8350\u4f7f\u7528\uff0c\u56e0\u4e3aNone\u662f\u4e00\u4e2a\u5355\u4f8b(singleton)\uff0c\u6574\u4e2aPython\u8fd0\u884c\u73af\u5883\u4e2d\u53ea\u6709\u4e00\u4e2aNone\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u201cis\u201d\u8fdb\u884cNone\u5224\u65ad<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8eNone\u7684\u6bd4\u8f83\uff0c\u4f7f\u7528\u201cis\u201d\u66f4\u5feb\u4e14\u8bed\u4e49\u66f4\u6e05\u6670\u3002None\u4ee3\u8868\u7a7a\u503c\u6216\u65e0\u503c\uff0c\u901a\u5e38\u7528\u4e8e\u53d8\u91cf\u521d\u59cb\u5316\u6216\u8868\u793a\u7279\u6b8a\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h4>\u5f15\u7528\u76f8\u540c\u5bf9\u8c61\u7684\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p>\u5f53\u4f60\u9700\u8981\u786e\u8ba4\u4e24\u4e2a\u53d8\u91cf\u662f\u5426\u771f\u7684\u5f15\u7528\u4e86\u540c\u4e00\u4e2a\u5bf9\u8c61\u65f6\uff0c\u4f7f\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u8fd9\u5728\u5904\u7406\u53ef\u53d8\u5bf9\u8c61\uff08\u5982\u5217\u8868\u3001\u5b57\u5178\u7b49\uff09\u65f6\u5c24\u5176\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4e0e\u201c==\u201d\u8fd0\u7b97\u7b26\u7684\u533a\u522b<\/h3>\n<\/p>\n<p><p>\u7406\u89e3\u201cis\u201d\u4e0e\u201c==\u201d\u4e4b\u95f4\u7684\u533a\u522b\u5bf9\u4e8e\u7f16\u5199\u6b63\u786e\u4e14\u6613\u4e8e\u7ef4\u62a4\u7684Python\u4ee3\u7801\u81f3\u5173\u91cd\u8981\u3002\u201cis\u201d\u7528\u4e8e\u8eab\u4efd\u6bd4\u8f83\uff0c\u201c==\u201d\u7528\u4e8e\u503c\u6bd4\u8f83\u3002<\/p>\n<\/p>\n<p><h4>\u8eab\u4efd\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u201cis\u201d\u68c0\u67e5\u4e24\u4e2a\u53d8\u91cf\u662f\u5426\u5f15\u7528\u5185\u5b58\u4e2d\u7684\u540c\u4e00\u4e2a\u5bf9\u8c61\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5982\u679c\u4e24\u4e2a\u53d8\u91cf\u7684id\u76f8\u540c\uff0c\u90a3\u4e48\u201cis\u201d\u7ed3\u679c\u4e3aTrue\u3002<\/p>\n<\/p>\n<p><h4>\u503c\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p>\u201c==\u201d\u68c0\u67e5\u4e24\u4e2a\u5bf9\u8c61\u7684\u503c\u662f\u5426\u76f8\u7b49\uff0c\u8fd9\u6d89\u53ca\u5230\u5bf9\u8c61\u7684<code>__eq__<\/code>\u65b9\u6cd5\uff0c\u53ef\u80fd\u4f1a\u8f83\u590d\u6742\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b9e\u9645\u793a\u4f8b\u89e3\u6790<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u793a\u4f8b\u6df1\u5316\u7406\u89e3\u201cis\u201d\u8fd0\u7b97\u7b26\u7684\u5b9e\u9645\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4e00\uff1a\u6bd4\u8f83\u4e0d\u53ef\u53d8\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u4e0d\u53ef\u53d8\u7c7b\u578b\uff0c\u5982\u6574\u6570\u548c\u5b57\u7b26\u4e32\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u88ab\u7f13\u5b58\uff0c\u4f7f\u7528\u201cis\u201d\u8fdb\u884c\u6bd4\u8f83\u6709\u65f6\u4f1a\u4ea7\u751f\u610f\u6599\u4e4b\u5916\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4e8c\uff1a\u6bd4\u8f83\u53ef\u53d8\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u5bf9\u53ef\u53d8\u7c7b\u578b\uff08\u5982\u5217\u8868\uff09\u8fdb\u884c\u201cis\u201d\u6bd4\u8f83\uff0c\u7ed3\u679c\u901a\u5e38\u66f4\u7b26\u5408\u76f4\u89c9\uff0c\u56e0\u4e3a\u53ef\u53d8\u5bf9\u8c61\u7684\u884c\u4e3a\u4e0d\u4f1a\u50cf\u4e0d\u53ef\u53d8\u5bf9\u8c61\u90a3\u6837\u6709\u7f13\u5b58\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4e00\u4e9b\u9677\u9631\u548c\u6700\u4f73\u5b9e\u8df5\uff0c\u4ee5\u907f\u514d\u5e38\u89c1\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h4>\u6ce8\u610f\u9690\u5f0f\u7f13\u5b58<\/h4>\n<\/p>\n<p><p>Python\u5bf9\u5c0f\u7684\u6574\u6570\u548c\u77ed\u5b57\u7b26\u4e32\u7b49\u4e0d\u53ef\u53d8\u5bf9\u8c61\u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u5bf9\u5b83\u4eec\u7684\u201cis\u201d\u6bd4\u8f83\u53ef\u80fd\u4ea7\u751f\u610f\u6599\u4e4b\u5916\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h4>\u907f\u514d\u5bf9\u666e\u901a\u503c\u4f7f\u7528\u201cis\u201d<\/h4>\n<\/p>\n<p><p>\u5c3d\u7ba1\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5bf9\u4e0d\u53ef\u53d8\u7c7b\u578b\u4f7f\u7528\u201cis\u201d\u770b\u4f3c\u6709\u6548\uff0c\u4f46\u8fd9\u662f\u7531\u4e8ePython\u5185\u90e8\u7684\u7f13\u5b58\u7b56\u7565\uff0c\u4e0d\u5e94\u4f9d\u8d56\u4e8e\u8fd9\u4e00\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u6df1\u5165\u7406\u89e3\u548c\u6b63\u786e\u5e94\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\uff0c\u53ef\u4ee5\u7f16\u5199\u66f4\u7cbe\u786e\u3001\u9ad8\u6548\u7684Python\u4ee3\u7801\u3002\u8bb0\u4f4f\u201cis\u201d\u662f\u6bd4\u8f83\u5bf9\u8c61\u6807\u8bc6\u7684\u5de5\u5177\uff0c\u800c\u975e\u6bd4\u8f83\u503c\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u7f16\u7a0b\u4e2d\u7684\u4e00\u4e9b\u5e38\u89c1\u9519\u8bef\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u4ec0\u4e48\u662fPython\u4e2d\u7684\u201cis\u201d\u8fd0\u7b97\u7b26\uff1f<\/strong><\/p>\n<p>Python\u4e2d\u7684\u201cis\u201d\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u6807\u8bc6\u662f\u5426\u76f8\u540c\uff0c\u5373\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u3002\u8fd9\u4e0e\u201c==\u201d\u8fd0\u7b97\u7b26\u4e0d\u540c\uff0c\u540e\u8005\u7528\u4e8e\u6bd4\u8f83\u5bf9\u8c61\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002<\/p>\n<p><strong>2. \u201cis\u201d\u8fd0\u7b97\u7b26\u548c\u201c==\u201d\u8fd0\u7b97\u7b26\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/p>\n<p>\u201cis\u201d\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u6807\u8bc6\uff0c\u5b83\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u3002\u800c\u201c==\u201d\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u503c\uff0c\u5b83\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4e24\u4e2a\u76f8\u540c\u7684\u6574\u6570\u5bf9\u8c61\uff0c\u5b83\u4eec\u7684\u503c\u76f8\u7b49\uff0c\u56e0\u6b64\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\u6bd4\u8f83\u65f6\u7ed3\u679c\u4e3aTrue\u3002\u4f46\u662f\uff0c\u5b83\u4eec\u53ef\u80fd\u5206\u522b\u6307\u5411\u5185\u5b58\u4e2d\u7684\u4e0d\u540c\u4f4d\u7f6e\uff0c\u56e0\u6b64\u4f7f\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\u6bd4\u8f83\u65f6\u7ed3\u679c\u4e3aFalse\u3002<\/p>\n<p><strong>3. \u4e3a\u4ec0\u4e48\u4f7f\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\u6bd4\u8f83\u5bf9\u8c61\u7684\u6807\u8bc6\uff1f<\/strong><\/p>\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6bd4\u8f83\u5bf9\u8c61\u7684\u6807\u8bc6\u53ef\u80fd\u66f4\u6709\u610f\u4e49\u3002\u5bf9\u4e8e\u4e0d\u53ef\u53d8\u5bf9\u8c61\uff08\u5982\u6574\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u7b49\uff09\uff0c\u5b83\u4eec\u7684\u503c\u76f8\u7b49\u65f6\u901a\u5e38\u53ef\u4ee5\u8ba4\u4e3a\u5b83\u4eec\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u4f7f\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\u6bd4\u8f83\u53ef\u4ee5\u66f4\u5feb\u5730\u5f97\u51fa\u7ed3\u679c\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5bf9\u4e8e\u81ea\u5b9a\u4e49\u7684\u5bf9\u8c61\uff0c\u53ef\u4ee5\u901a\u8fc7\u91cd\u5199\u5bf9\u8c61\u7684__eq__\u65b9\u6cd5\u6765\u5b9a\u4e49\u201c==\u201d\u8fd0\u7b97\u7b26\u7684\u884c\u4e3a\uff0c\u4f46\u65e0\u6cd5\u91cd\u5199\u201cis\u201d\u8fd0\u7b97\u7b26\u3002\u56e0\u6b64\u5728\u6bd4\u8f83\u5bf9\u8c61\u7684\u6807\u8bc6\u65f6\uff0c\u4f7f\u7528\u201cis\u201d\u8fd0\u7b97\u7b26\u662f\u66f4\u53ef\u9760\u548c\u65b9\u4fbf\u7684\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u201cis\u201d\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u6807\u8bc6\uff08identity\uff09\uff0c\u800c\u4e0d\u662f\u5b83\u4eec\u7684\u503c\u3002\u5f53\u6211\u4eec\u4f7f\u7528\u201cis\u201d [&hellip;]","protected":false},"author":3,"featured_media":178968,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/178910"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=178910"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/178910\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/178968"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=178910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=178910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=178910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}