{"id":3014,"date":"2025-05-29T16:10:16","date_gmt":"2025-06-04T09:09:16","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3014"},"modified":"2025-06-04T16:10:16","modified_gmt":"2025-06-04T09:09:16","slug":"python%e4%b8%ad%e7%9a%84id%e5%87%bd%e6%95%b8%ef%bc%9a%e7%9e%ad%e8%a7%a3%e5%ae%83%e7%9a%84%e5%8a%9f%e8%83%bd%e5%92%8c%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/python%e4%b8%ad%e7%9a%84id%e5%87%bd%e6%95%b8%ef%bc%9a%e7%9e%ad%e8%a7%a3%e5%ae%83%e7%9a%84%e5%8a%9f%e8%83%bd%e5%92%8c%e7%94%a8%e6%b3%95\/","title":{"rendered":"\u6df1\u5165\u7406\u89e3 Python \u4e2d\u7684 id() \u51fd\u6578\uff1a\u529f\u80fd\u3001\u7528\u6cd5\u53ca\u6700\u4f73\u5be6\u8e10 (2025 \u6700\u65b0)"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Python, id(), Python \u6559\u5b78, Python \u5167\u5efa\u51fd\u6578\"><\/p>\n<h1>\u6df1\u5165\u7406\u89e3 Python \u4e2d\u7684 id() \u51fd\u6578<\/h1>\n<p>Python \u4e2d\u7684 `id()` \u51fd\u6578\u662f\u4e00\u500b\u5167\u5efa\u51fd\u6578\uff0c\u80fd\u5920\u7528\u4f86\u53d6\u5f97\u7269\u4ef6\u7684\u8b58\u5225\u78bc\u3002\u9019\u500b\u8b58\u5225\u78bc\u662f\u7269\u4ef6\u5728\u8a18\u61b6\u9ad4\u4e2d\u7684\u4f4d\u7f6e\uff0c\u901a\u5e38\u4ee5\u6574\u6578\u5f62\u5f0f\u56de\u50b3\u3002\u4e86\u89e3 `id()` \u51fd\u6578\u4e0d\u50c5\u80fd\u5e6b\u52a9\u6211\u5011\u8abf\u8a66\u7a0b\u5f0f\uff0c\u9084\u80fd\u5920\u6df1\u5165\u7406\u89e3 Python \u7684\u7269\u4ef6\u6a21\u578b\u3002<\/p>\n<h2>id() \u51fd\u6578\u7684\u4f7f\u7528\u65b9\u6cd5<\/h2>\n<p>\u4f7f\u7528 `id()` \u51fd\u6578\u975e\u5e38\u7c21\u55ae\u3002\u60a8\u53ea\u9700\u5c07\u4e00\u500b\u7269\u4ef6\u4f5c\u70ba\u53c3\u6578\u50b3\u5165\u51fd\u6578\u4e2d\uff0c\u5373\u53ef\u7372\u5f97\u8a72\u7269\u4ef6\u7684\u8b58\u5225\u78bc\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u4f7f\u7528\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`python<br \/>\na = 10<br \/>\nprint(id(a))<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\u53ef\u80fd\u985e\u4f3c\u65bc\uff1a<\/p>\n<p>&#8220;`<br \/>\n140735003799456<br \/>\n&#8220;`<\/p>\n<p>\u9019\u4ee3\u8868 `a` \u7684\u8b58\u5225\u78bc\u70ba `140735003799456`\uff0c\u986f\u793a\u8a72\u7269\u4ef6\u5728\u8a18\u61b6\u9ad4\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<h2>id() \u51fd\u6578\u7684\u512a\u9ede<\/h2>\n<p>`id()` \u51fd\u6578\u7684\u4e00\u5927\u512a\u9ede\u662f\u5b83\u53ef\u7528\u4f86\u6aa2\u67e5\u5169\u500b\u7269\u4ef6\u662f\u5426\u70ba\u540c\u4e00\u500b\u7269\u4ef6\u3002\u4f8b\u5982\uff1a<\/p>\n<p>&#8220;`python<br \/>\na = 10<br \/>\nb = 10<br \/>\nprint(id(a) == id(b))<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\u70ba\uff1a<\/p>\n<p>&#8220;`<br \/>\nTrue<br \/>\n&#8220;`<\/p>\n<p>\u9019\u610f\u5473\u8457 `a` \u548c `b` \u662f\u540c\u4e00\u500b\u7269\u4ef6\uff0c\u56e0\u6b64\u5b83\u5011\u7684\u8b58\u5225\u78bc\u76f8\u540c\u3002<\/p>\n<h2>id() \u51fd\u6578\u7684\u7f3a\u9ede<\/h2>\n<p>\u5118\u7ba1 `id()` \u51fd\u6578\u975e\u5e38\u6709\u7528\uff0c\u4f46\u5b83\u4e5f\u6709\u4e00\u4e9b\u9650\u5236\u3002\u5b83\u50c5\u80fd\u6aa2\u67e5\u7269\u4ef6\u7684\u8b58\u5225\u78bc\uff0c\u800c\u7121\u6cd5\u5c0d\u6bd4\u7269\u4ef6\u7684\u985e\u578b\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u7bc4\uff1a<\/p>\n<p>&#8220;`python<br \/>\na = 10<br \/>\nb = 20<br \/>\nprint(id(a) == id(b))<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\u70ba\uff1a<\/p>\n<p>&#8220;`<br \/>\nFalse<br \/>\n&#8220;`<\/p>\n<p>\u9019\u8868\u793a `a` \u548c `b` \u662f\u4e0d\u540c\u7684\u7269\u4ef6\uff0c\u56e0\u800c\u64c1\u6709\u4e0d\u540c\u7684\u8b58\u5225\u78bc\u3002<\/p>\n<h2>id() \u51fd\u6578\u7684\u61c9\u7528<\/h2>\n<p>`id()` \u51fd\u6578\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u7406\u89e3\u7269\u4ef6\u7684\u8eab\u4efd\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u8907\u96dc\u8cc7\u6599\u7d50\u69cb\u6642\u3002\u4f8b\u5982\uff0c\u5c0d\u65bc\u5217\u8868\uff1a<\/p>\n<p>&#8220;`python<br \/>\na = [1, 2, 3]\nb = [1, 2, 3]\nprint(id(a) == id(b))<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\u70ba\uff1a<\/p>\n<p>&#8220;`<br \/>\nFalse<br \/>\n&#8220;`<\/p>\n<p>\u56e0\u70ba\u96d6\u7136 `a` \u548c `b` \u770b\u8d77\u4f86\u76f8\u540c\uff0c\u4f46\u5b83\u5011\u5be6\u969b\u4e0a\u662f\u5169\u500b\u4e0d\u540c\u7684\u7269\u4ef6\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528 `id()` \u51fd\u6578\u6aa2\u67e5\u7269\u4ef6\u7684\u985e\u578b\uff0c\u4ee5\u4e0b\u662f\u4e00\u500b\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`python<br \/>\na = 10<br \/>\nb = 20<br \/>\nprint(type(a) == type(b))<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\u70ba\uff1a<\/p>\n<p>&#8220;`<br \/>\nTrue<br \/>\n&#8220;`<\/p>\n<p>\u9019\u610f\u5473\u8457 `a` \u548c `b` \u662f\u540c\u4e00\u985e\u578b\u7684\u7269\u4ef6\u3002<\/p>\n<h2>\u6700\u4f73\u5be6\u8e10\u8207\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528 `id()` \u51fd\u6578\u6642\uff0c\u61c9\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<p>1. `id()` \u51fd\u6578\u8fd4\u56de\u7684\u662f\u7269\u4ef6\u5728\u751f\u547d\u9031\u671f\u5167\u7684\u552f\u4e00\u8b58\u5225\u78bc\uff0c\u4f46\u4e00\u65e6\u7269\u4ef6\u88ab\u92b7\u6bc0\uff0c\u8a72\u8b58\u5225\u78bc\u53ef\u80fd\u6703\u88ab\u91cd\u7528\u3002<br \/>\n2. \u4e0d\u8981\u50c5\u4f9d\u8cf4 `id()` \u4f86\u9032\u884c\u7269\u4ef6\u6bd4\u8f03\uff0c\u82e5\u8981\u6bd4\u8f03\u5169\u500b\u7269\u4ef6\u7684\u503c\uff0c\u61c9\u4f7f\u7528 `==` \u96b1\u5f0f\u6bd4\u8f03\u3002<\/p>\n<p>\u82e5\u60f3\u9032\u4e00\u6b65\u4e86\u89e3 Python \u7684\u5167\u5efa\u51fd\u6578\uff0c\u5efa\u8b70\u53c3\u8003 [\u9019\u7bc7\u6587\u7ae0](https:\/\/vocus.cc\/article\/5f7b1c7dd6a505001c82f6fa) \u4f86\u64f4\u5c55\u60a8\u7684\u77e5\u8b58\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>Python \u4e2d\u7684 `id()` \u51fd\u6578\u662f\u4e00\u500b\u91cd\u8981\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u7406\u89e3\u7269\u4ef6\u7684\u8b58\u5225\u78bc\u53ca\u5176\u5728\u8a18\u61b6\u9ad4\u4e2d\u7684\u4f4d\u7f6e\u3002\u7121\u8ad6\u662f\u5728\u8abf\u8a66\u9084\u662f\u5be6\u4f5c\u904e\u7a0b\u4e2d\uff0c\u6b63\u78ba\u4f7f\u7528 `id()` \u51fd\u6578\u5c07\u80fd\u63d0\u9ad8\u60a8\u7684\u7a0b\u5f0f\u8a2d\u8a08\u80fd\u529b\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<p>**Q1: \u70ba\u4ec0\u9ebc id() \u51fd\u6578\u7684\u8fd4\u56de\u503c\u5c0d\u65bc\u7406\u89e3 Python \u7684\u7269\u4ef6\u6a21\u578b\u5f88\u91cd\u8981\uff1f**<br \/>\nA1: `id()` \u51fd\u6578\u7684\u8fd4\u56de\u503c\u8b93\u958b\u767c\u8005\u80fd\u5920\u78ba\u5b9a\u7269\u4ef6\u7684\u8eab\u4efd\uff0c\u9019\u5c0d\u65bc\u907f\u514d\u610f\u5916\u4fee\u6539\u540c\u4e00\u500b\u7269\u4ef6\u81f3\u95dc\u91cd\u8981\uff0c\u7279\u5225\u662f\u5728\u8655\u7406 mutable \u7269\u4ef6\u6642\u3002<\/p>\n<p>**Q2: `id()` \u548c `is` \u904b\u7b97\u7b26\u6709\u4ec0\u9ebc\u5340\u5225\uff1f**<br \/>\nA2: `id()` \u8fd4\u56de\u7269\u4ef6\u7684\u8b58\u5225\u78bc\uff0c\u800c `is` \u904b\u7b97\u7b26\u7528\u65bc\u6aa2\u67e5\u5169\u500b\u7269\u4ef6\u662f\u5426\u70ba\u540c\u4e00\u500b\u5be6\u4f8b\u3002\u4e8c\u8005\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u5e38\u5e38\u914d\u5408\u4f7f\u7528\u3002<\/p>\n<p>**Q3: \u5982\u4f55\u4f7f\u7528 `id()` \u51fd\u6578\u4f86\u8abf\u8a66\u6211\u7684 Python \u7a0b\u5f0f\uff1f**<br \/>\nA3: \u5728\u8abf\u8a66\u904e\u7a0b\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 `id()` \u51fd\u6578\u4f86\u78ba\u8a8d\u8b8a\u6578\u6240\u6307\u5411\u7684\u7269\u4ef6\u662f\u5426\u767c\u751f\u4e86\u8b8a\u5316\uff0c\u9019\u5c0d\u65bc\u7406\u89e3\u8cc7\u6599\u6d41\u5411\u548c\u907f\u514d\u932f\u8aa4\u975e\u5e38\u6709\u5e6b\u52a9\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>id()\u51fd\u6578\u662fPython\u4e2d\u7684\u4e00\u500b\u5167\u7f6e\u51fd\u6578\uff0c\u5b83\u53ef\u4ee5\u8fd4\u56de\u4e00\u500b\u5c0d\u8c61\u7684\u552f\u4e00\u8b58\u5225\u78bc\uff0c\u53ef\u4ee5\u7528\u65bc\u6bd4\u8f03\u5c0d\u8c61\u7684\u76f8\u7b49\u6027\uff0c\u4ee5\u53ca\u67e5\u770b\u5c0d\u8c61\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39id()\u51fd\u6578\u7684\u529f\u80fd\u548c\u7528\u6cd5\uff0c\u4ee5\u53ca\u5b83\u5728Python\u4e2d\u7684\u61c9\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":2518,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18],"tags":[15],"class_list":["post-3014","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2022\/12\/DALL\u00b7E-2022-12-28-14.25.55-\u62f7\u8c9d2.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-MC","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=3014"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3014\/revisions"}],"predecessor-version":[{"id":12963,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3014\/revisions\/12963"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/2518"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}