{"id":178070,"date":"2022-04-19T02:12:21","date_gmt":"2022-04-18T18:12:21","guid":{"rendered":"http:\/\/www.idc.net\/help\/178070\/"},"modified":"2022-04-19T02:12:21","modified_gmt":"2022-04-18T18:12:21","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e6%80%8e%e4%b9%88%e5%88%a4%e6%96%ad%e6%9f%90%e4%b8%80%e5%af%b9%e8%b1%a1%e6%98%af%e5%90%a6%e4%b8%ba%e5%ad%97%e5%85%b8","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/178070\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u600e\u4e48\u5224\u65ad\u67d0\u4e00\u5bf9\u8c61\u662f\u5426\u4e3a\u5b57\u5178"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/article\/000\/000\/004\/5d60cb7e4bd6c747.jpg\" class=\"aligncenter\"><\/p>\n<p>\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5728\u4ee3\u7801\u4e2d\u786e\u5b9a\u67d0\u4e2a\u5b9e\u4f8b\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\u3002\u901a\u8fc7type\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u5177\u4f53\u7684\u7c7b\u578b\u540d\u79f0\u3002\u53e6\u6709\u4e00\u4e9b\u573a\u666f\u4e0b\uff0c\u53ea\u9700\u8981\u77e5\u9053\u5b9e\u4f8b\u662f\u5426\u5c5e\u4e8e\u67d0\u4e00\u4e9b\u7c7b\u578b\u4e4b\u4e00\u3002\u4f8b\u5982\u8981\u904d\u5386\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8981\u5148\u5224\u65ad\u8be5\u5b9e\u4f8b\u662f\u5426\u4e3a\u5143\u7ec4\u3001\u5217\u8868\u6216\u5b57\u5178\u7b49\u53ef\u8fed\u4ee3\u7c7b\u578b\u4e4b\u4e00\u3002\u901a\u8fc7isinstance\u51fd\u6570\u53ef\u4ee5\u8fbe\u5230\u6b64\u76ee\u7684\u3002<\/p>\n<p><strong>isinstance(object,classinfo)<br \/><\/strong>\u8fd9\u4e2a\u51fd\u6570\u7684\u529f\u80fd\u7b80\u5355\u7684\u8bf4\u5c31\u662f\u5224\u65adobject\u5b9e\u4f8b\u662f\u5426\u662fclassinfo\u7c7b\u578b\u7684\uff0c\u5982\u679c\u662f\u5219\u8fd4\u56deTRUE,\u5426\u5219\u8fd4\u56deFALSE\u3002classinfo\u53c2\u6570\u6709\u4e09\u79cd\u60c5\u51b5<br \/>1.\u7c7b\u578b\uff0c\u53ef\u4ee5\u662f\u57fa\u672c\u7684\u5185\u7f6e\u6570\u636e\u7c7b\u578b\u6216\u81ea\u5b9a\u4e49\u7684\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>isinstance(object,str)\nisinstance(object,classA)<\/pre>\n<p>2.\u65b0\u5f0f\u7c7b\u578b(new-style class)\uff0c\u5373type object\uff0c\u76f8\u5173\u4ecb\u7ecd\u53c2\u89c1\uff1ahttp:\/\/wiki.woodpecker.org.cn\/moin\/PyTypesAndObjects<\/p>\n<p>\u8c03\u7528\u65b9\u5f0f\u540c\u4e0a\u3002<\/p>\n<p>3.\u5143\u7ec4\uff0c\u6839\u636e\u5143\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\uff0c\u53ef\u4ee5\u8fd9\u6837\u6df7\u642d<\/p>\n<p>1)\u5143\u7d20\u662fclass\u6216type object\u7684\u5143\u7ec4\uff0c\u4f8b\u5982<\/p>\n<pre>isinstance(obj,(list,tuple))<\/pre>\n<p>2)\u5143\u7d20\u672c\u8eab\u662f\u5143\u7ec4\uff0c\u4f8b\u5982<\/p>\n<pre>isinstance(obj,((classA,classB),(classC,classD),(classE,classF)))<\/pre>\n<p>3)\u5143\u7d20\u672c\u8eab\u662f\u5143\u7ec4\u548cclass\u6216type object\u7684\u7ec4\u5408\uff1b<\/p>\n<pre>isinstance(obj,((classA,classB),(classC,classD),(classE,classF),str))<\/pre>\n<p>\u53e6\u5916\uff0c\u5982\u679cobject\u662fclassinfo\u6240\u4ee3\u8868\u7684\u7c7b\u578b\u6216\u5176\u5143\u7ec4\u4e2d\u7684\u7c7b\u578b\u7684\u5b50\u7c7b\uff0c\u540c\u6837\u8fd4\u56deTRUE\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5728\u4ee3\u7801\u4e2d\u786e\u5b9a\u67d0\u4e2a\u5b9e\u4f8b\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\u3002\u901a\u8fc7type\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u5177\u4f53\u7684\u7c7b\u578b\u540d\u79f0\u3002\u53e6\u6709\u4e00\u4e9b\u573a\u666f\u4e0b\uff0c\u53ea\u9700\u8981\u77e5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":178071,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-178070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/178070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=178070"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/178070\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/178071"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=178070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=178070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=178070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}