{"id":176979,"date":"2023-07-29T13:47:25","date_gmt":"2023-07-29T05:47:25","guid":{"rendered":"http:\/\/www.idc.net\/help\/176979\/"},"modified":"2023-07-29T13:47:25","modified_gmt":"2023-07-29T05:47:25","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e4%b8%ad%e7%9a%84%e5%a4%9a%e6%80%81%e6%80%8e%e4%b9%88%e7%90%86%e8%a7%a3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/176979\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1aPython\u4e2d\u7684\u591a\u6001\u600e\u4e48\u7406\u89e3\uff1f"},"content":{"rendered":"<p>Python\u662f\u4e00\u95e8\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5728Python\u4e2d\u4e00\u5207\u7686\u5bf9\u8c61\uff0c\u9762\u5411\u5bf9\u8c61\u6709\u4e09\u5927\u7279\u6027\uff1a\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3002<\/p>\n<p>\u5728Python\u4e2d\u4ec0\u4e48\u662f\u591a\u6001\u5462\uff1f\u987e\u540d\u601d\u4e49\uff0c\u591a\u6001\u5c31\u662f\u591a\u79cd\u8868\u73b0\u5f62\u6001\u7684\u610f\u601d\u3002\u5b83\u662f\u4e00\u79cd\u673a\u5236\u3001\u4e00\u79cd\u80fd\u529b\uff0c\u800c\u975e\u67d0\u4e2a\u5173\u952e\u5b57\u3002\u5b83\u5728\u7c7b\u7684\u7ee7\u627f\u4e2d\u5f97\u4ee5\u5b9e\u73b0\uff0c\u5728\u7c7b\u7684\u65b9\u6cd5\u8c03\u7528\u4e2d\u5f97\u4ee5\u4f53\u73b0\u3002\u591a\u6001\u610f\u5473\u7740\u53d8\u91cf\u5e76\u4e0d\u77e5\u9053\u5f15\u7528\u7684\u5bf9\u8c61\u662f\u4ec0\u4e48\uff0c\u6839\u636e\u5f15\u7528\u5bf9\u8c61\u7684\u4e0d\u540c\u8868\u73b0\u4e0d\u540c\u7684\u884c\u4e3a\u65b9\u5f0f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/article\/000\/000\/002\/5d07058b1c14d699.jpg\" class=\"aligncenter\"><\/p>\n<p>\u6211\u4eec\u5148\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c<strong>\u8fd0\u7b97\u7b26\u591a\u6001\uff1a<\/strong><\/p>\n<pre>a=34\nb=57\nprint(a+b)\na=\"\u4e16\u754c\"\nb=\"\u4f60\u597d\"\nprint(a+b)<\/pre>\n<p>\u6211\u4eec\u4e0d\u77e5\u9053+\u6cd5\u8fd0\u7b97\u7b26\u5de6\u53f3\u4e24\u4e2a\u53d8\u91cf\u662f\u4ec0\u4e48\u7c7b\u578b\uff0c\u5f53\u6211\u4eec\u7ed9\u7684\u662fint\u7c7b\u578b\u65f6\uff0c\u5b83\u5c31\u8fdb\u884c\u52a0\u6cd5\u8fd0\u7b97\u3002\u5f53\u6211\u4eec\u7ed9\u7684\u662f\u5b57\u7b26\u4e32\u7c7b\u578b\u65f6\uff0c\u5b83\u5c31\u8fd4\u56de\u7684\u662f\u4e24\u4e2a\u5b57\u7b26\u4e32\u62fc\u63a5\u7684\u7ed3\u679c\u3002\u4e5f\u5c31\u662f\u6839\u636e\u53d8\u91cf\u7c7b\u578b\u7684\u4e0d\u540c\uff0c\u8868\u73b0\u4e0d\u80fd\u7684\u5f62\u6001\u3002<\/p>\n<p>\u6211\u4eec\u518d\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50\uff0c<strong>\u65b9\u6cd5\u591a\u6001\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aMyClass.py\u7684\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b<\/p>\n<pre>__author__=&nbsp;'MXi4oyu'\nclassPeople:\n&nbsp;&nbsp;def&nbsp;say(self):\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"\u5927\u5bb6\u597d\uff01\")\nclassStudent:\n&nbsp;&nbsp;def&nbsp;say(self):\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"\u8001\u5e08\u597d\uff01\")<\/pre>\n<p>\u6211\u4eec\u518d\u521b\u5efa\u4e00\u4e2aMain.py\u7684\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>__author__=&nbsp;'MXi4oyu'\nfromrandom&nbsp;import&nbsp;choice\nimportMyClass\np1=MyClass.People()\nstu1=MyClass.Student()\n#\u901a\u8fc7choice\u65b9\u6cd5\u6211\u4eec\u53ef\u4ee5\u968f\u673a\u9009\u62e9\u5217\u8868\u4e2d\u7684\u67d0\u4e00\u9879\nobj=choice([p1,stu1])&nbsp;\nprint(type(obj))\nobj.say()<\/pre>\n<p>\u6211\u4eec\u521b\u5efa\u7684\u4e34\u65f6\u5bf9\u8c61obj\u662f\u7531\u968f\u673a\u51fd\u6570\u53d6\u51fa\u6765\u7684\uff0c\u6211\u4eec\u4e0d\u77e5\u9053\u5b83\u7684\u5177\u4f53\u7c7b\u578b\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u76f8\u540c\u7684\u64cd\u4f5c\u3002\u5373\u8ba9\u5b83\u8c03\u7528say\u65b9\u6cd5\uff0c\u7136\u540e\u6839\u636e\u5176\u7c7b\u578b\u7684\u4e0d\u540c\uff0c\u5b83\u6240\u8868\u73b0\u7684\u884c\u4e3a\u4e0d\u540c\u3002\u8fd9\u5c31\u662f\u591a\u6001\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u662f\u4e00\u95e8\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5728Python\u4e2d\u4e00\u5207\u7686\u5bf9\u8c61\uff0c\u9762\u5411\u5bf9\u8c61\u6709\u4e09\u5927\u7279\u6027\uff1a\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3002 \u5728P [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":176980,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-176979","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\/176979","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=176979"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/176979\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/176980"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=176979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=176979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=176979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}