{"id":169034,"date":"2022-04-21T13:35:35","date_gmt":"2022-04-21T05:35:35","guid":{"rendered":"http:\/\/www.idc.net\/help\/169034\/"},"modified":"2022-04-21T13:35:35","modified_gmt":"2022-04-21T05:35:35","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e6%98%af%e5%90%a6%e6%94%af%e6%8c%81%e9%87%8d%e8%bd%bd","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/169034\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u662f\u5426\u652f\u6301\u91cd\u8f7d"},"content":{"rendered":"<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/article\/000\/000\/003\/5d7ef8ca49a24975.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5728\u4e00\u4e9b\u9759\u6001\u8bed\u8a00\u4e2d\uff0c\u5927\u90fd\u5b58\u5728\u6709\u4e00\u4e2a\u91cd\u8f7d\u7684\u6982\u5ff5\u3002\u8fd9\u662f\u5728OOP\uff08\u9762\u5bf9\u5bf9\u8c61\u7f16\u7a0b\uff09\u4e2d\u4e00\u4e2a\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u4e2a\u884c\u4e3a\u3002<\/p>\n<p>\u6240\u8c13\u91cd\u8f7d\uff0c\u5c31\u662f\u591a\u4e2a\u76f8\u540c\u51fd\u6570\u540d\u7684\u51fd\u6570\uff0c\u6839\u636e\u4f20\u5165\u7684\u53c2\u6570\u4e2a\u6570\uff0c\u53c2\u6570\u7c7b\u578b\u800c\u6267\u884c\u4e0d\u540c\u7684\u529f\u80fd\u3002\u6240\u4ee5\u51fd\u6570\u91cd\u8f7d\u5b9e\u8d28\u4e0a\u662f\u4e3a\u4e86\u89e3\u51b3\u7f16\u7a0b\u4e2d\u53c2\u6570\u53ef\u53d8\u4e0d\u7edf\u4e00\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>python \u4e2d\u7684\u91cd\u8f7d<\/strong><\/p>\n<p>\u5728python\u4e2d\uff0c\u5177\u6709\u91cd\u8f7d\u7684\u601d\u60f3\u5374\u6ca1\u6709\u91cd\u8f7d\u7684\u6982\u5ff5\u3002\u6240\u4ee5\u6709\u7684\u4eba\u8bf4python\u8fd9\u95e8\u8bed\u8a00\u5e76\u4e0d\u652f\u6301\u51fd\u6570\u91cd\u8f7d\uff0c\u6709\u7684\u4eba\u8bf4python\u5177\u6709\u91cd\u8f7d\u529f\u80fd\u3002\u5b9e\u9645\u4e0apython\u7f16\u7a0b\u4e2d\u5177\u6709\u91cd\u8f7d\u7684\u76ee\u7684\uff0c\u5374\u65e0\u91cd\u8f7d\u7684\u884c\u4e3a\uff0c\u6216\u8005\u8bf4\u662fpython\u5e76\u4e0d\u9700\u8981\u91cd\u8f7d\uff01<\/p>\n<p>python\u662f\u4e00\u95e8\u52a8\u6001\u8bed\u8a00\uff0c\u4e0d\u9700\u8981\u58f0\u660e\u53d8\u91cf\u7c7b\u578b\uff0c\u51fd\u6570\u4e2d\u53ef\u4ee5\u63a5\u53d7\u4efb\u4f55\u7c7b\u578b\u7684\u53c2\u6570\u4e5f\u5c31\u65e0\u6cd5\u6839\u636e\u53c2\u6570\u7c7b\u578b\u6765\u652f\u6301\u91cd\u8f7d\uff0cpython\u6ca1\u6709\u5fc5\u8981\u53bb\u8003\u8651\u53c2\u6570\u7684\u7c7b\u578b\u95ee\u9898\uff0c\u8fd9\u4e9b\u90fd\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u5224\u65ad\u5904\u7406\uff0c\u5e76\u65e0\u5fc5\u8981\u53bb\u5728\u5199\u4e00\u4e2a\u51fd\u6570\u3002python \u6709\u591a\u79cd\u4f20\u53c2\u65b9\u5f0f\uff0c\u9ed8\u8ba4\u53c2\u6570\/\u53ef\u53d8\u53c2\u6570\/\u53ef\u53d8\u5173\u952e\u5b57\u53c2\u6570\u53ef\u4ee5\u5904\u7406\u51fd\u6570\u53c2\u6570\u4e2d\u53c2\u6570\u53ef\u53d8\u7684\u95ee\u9898\u3002<\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a\u300aPython\u6559\u7a0b\u300b<\/p>\n<p><strong>python3.4\u4e2d\u589e\u52a0\u7684\u91cd\u8f7d\u673a\u5236<\/strong><\/p>\n<p>\u5728python3.4\u4e2d\u63d0\u4f9b\u6709\u4e00\u4e2a\u8f6c\u53d1\u673a\u5236\u6765\u5b9e\u73b0\u91cd\u8f7d\uff1a<\/p>\n<pre>from&nbsp;functools&nbsp;import&nbsp;singledispatch&nbsp;&nbsp;&nbsp;\n@singledispatch&nbsp;\ndef&nbsp;function(obj):&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;print('%r'%(obj))\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n@function.register(int)&nbsp;\ndef&nbsp;function_int(obj):&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;print('Integer:&nbsp;%d'%(obj))&nbsp;\n&nbsp;&nbsp;\n@function.register(str)&nbsp;\ndef&nbsp;function_int(obj):&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;print('String:&nbsp;%s'%(obj))&nbsp;\n&nbsp;&nbsp;\n@function.register(list)&nbsp;\ndef&nbsp;function_list(obj):&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;print('List:&nbsp;%r'%(obj))&nbsp;\n&nbsp;&nbsp;\n&nbsp;&nbsp;\nif&nbsp;__name__&nbsp;==&nbsp;\"__main__\":&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function(1)&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function('hello')&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function(range(3))&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function(object)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e00\u4e9b\u9759\u6001\u8bed\u8a00\u4e2d\uff0c\u5927\u90fd\u5b58\u5728\u6709\u4e00\u4e2a\u91cd\u8f7d\u7684\u6982\u5ff5\u3002\u8fd9\u662f\u5728OOP\uff08\u9762\u5bf9\u5bf9\u8c61\u7f16\u7a0b\uff09\u4e2d\u4e00\u4e2a\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u4e2a\u884c\u4e3a\u3002 \u6240\u8c13\u91cd\u8f7d\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":169035,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-169034","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\/169034","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=169034"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/169034\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/169035"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=169034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=169034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=169034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}