{"id":165824,"date":"2020-10-10T20:24:31","date_gmt":"2020-10-10T12:24:31","guid":{"rendered":"http:\/\/4563.org\/?p=165824"},"modified":"2020-10-10T20:24:31","modified_gmt":"2020-10-10T12:24:31","slug":"%e6%9c%a8%e5%85%b0%e9%87%8d%e7%94%9f%ef%bc%9a%e4%b8%8e-python-%e7%94%9f%e6%80%81%e7%9a%84%e5%85%bc%e5%ae%b9%e9%97%ae%e9%a2%98%ef%bc%9b%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%8f%92%e5%80%bc","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=165824","title":{"rendered":"\u6728\u5170\u91cd\u751f\uff1a\u4e0e Python \u751f\u6001\u7684\u517c\u5bb9\u95ee\u9898\uff1b\u5b57\u7b26\u4e32\u63d2\u503c"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6728\u5170\u91cd\u751f\uff1a\u4e0e Python \u751f\u6001\u7684\u517c\u5bb9\u95ee\u9898\uff1b\u5b57\u7b26\u4e32\u63d2\u503c               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuanwu <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1a\u6728\u5170\u91cd\u751f\uff1a\u4e0e Python \u751f\u6001\u7684\u517c\u5bb9\u95ee\u9898\uff1b\u5b57\u7b26\u4e32\u63d2\u503c<\/p>\n<p><em><strong>\u8282\u9009\uff1a<\/strong><\/em><\/p>\n<p>\u524d\u4e24\u5929\u7528\u6728\u5170\u8c03\u7528 pygame \u5e93\u5b9e\u73b0\u4e86\u4e2a\u4e95\u5b57\u68cb\u68cb\u76d8\u754c\u9762\u3002\u671f\u95f4\u9047\u5230\u4e86\u4e00\u4e9b\u95ee\u9898\uff0c\u5148\u5c0f\u7ed3\u4e00\u4e0b\u3002<\/p>\n<h2>1 \u751f\u6001\u517c\u5bb9\u95ee\u9898<\/h2>\n<p><em><strong>\u6ce8\uff1a\u89e3\u51b3\u65b9\u6cd5\u9650\u4e8e\u4e2a\u4eba\u81f3\u4eca\u5bf9\u6728\u5170\u548c Python \u7684\u4e86\u89e3\u3002\u5982\u6709\u9ad8\u62db\uff0c\u70e6\u8bf7\u6307\u6559\uff01<\/strong><\/em><\/p>\n<h2>1.1 \u5143\u7ec4 \uff08 tuple \uff09<\/h2>\n<p>python \u4e2d\u5f88\u5e38\u7528\u7684\u7ed3\u6784\uff0c\u53ef\u4ee5\u5982\u4e0b\u521d\u59cb\u5316\uff1a<\/p>\n<pre><code>&gt;&gt;&gt; t = (1,2) &gt;&gt;&gt; t (1, 2) &gt;&gt;&gt; t = 2, 3 &gt;&gt;&gt; t (2, 3) <\/code><\/pre>\n<p>\u4f46\u6728\u5170\u4e2d\u597d\u50cf\u6ca1\u627e\u5230\u7c7b\u4f3c\u7684\u7b80\u4fbf\u65b9\u6cd5\u3002\u5e78\u597d\u4e0e python \u76f8\u4f3c\uff0c\u51fd\u6570\u8fd4\u56de\u591a\u9879\u65f6\u5c31\u4f1a\u6253\u5305\u6210\u5143\u7ec4\uff0c\u56e0\u6b64\u6682\u65f6\u8fd9\u6837\u5b9a\u4e49\u51fd\u6570\uff1a<\/p>\n<pre><code>func \u591a\u9879 2(a, b) {   return a, b } func \u591a\u9879 3(a, b, c) {   return a, b, c } ... <\/code><\/pre>\n<p>\u4e4b\u540e\u652f\u6301\u53d8\u957f\u53c2\u6570\u65f6\uff0c\u5c31\u53ef\u4ee5\u5408\u5e76\u4e3a\u4e00\u4e2a\u51fd\u6570\u4e86\u3002<\/p>\n<h3>1.2 \u5982\u4f55\u5f15\u7528 type \u5c5e\u6027<\/h3>\n<p>\u4e0b\u9762\u662f pygame \u7684\u5e38\u89c1\u64cd\u4f5c\uff0c\u68c0\u67e5 pygame.event \u7684 type\uff1a<\/p>\n<pre><code>   for event in pygame.event.get():     if event.type == pygame.QUIT : <\/code><\/pre>\n<p>\u4f46\u6728\u5170\u4e2d\u7684 type \u662f\u7c7b\u578b\u5b9a\u4e49\u7684\u5173\u952e\u8bcd\uff0c\u56e0\u800c\u5982\u679c\u4ecd\u4f7f\u7528 .type \u4f1a\u62a5\u9519\u3002\u521a\u9047\u5230\u8fd9\u4e00\u95ee\u9898\u65f6\uff0c\u9887\u4e3a\u9707\u60ca\uff0c\u4ee5\u4e3a\u53d1\u73b0\u4e86\u6728\u5170\u7684\u4e00\u4e2a\u5927\u786c\u4f24\uff0c\u4e0d\u8fc7\u8fd8\u597d python \u8fd8\u6709\u4e00\u4e2a <code>__getattribute__('type')<\/code> \u53ef\u7528\u3002\u4f46\u53e6\u4e00\u79cd\u65b9\u6cd5\u7528\u5728\u8fd9\u91cc\u5c31\u65e0\u6cd5\u83b7\u5f97 type \u503c\uff1a<\/p>\n<pre><code>func getType(\u4e2a\u4f53) {   for \u5c5e\u6027, \u503c in \u4e2a\u4f53.__dict__.items() {    return \u503c if \u5c5e\u6027 == 'type'   } } <\/code><\/pre>\n<p>\u5927\u6982\u56e0\u4e3a\u8fd9\u4e2a type \u662f\u4e2a @property \uff08\u6728\u5170\u4e2d\u7684\u5e94\u53d8\u5c5e\u6027\uff09\uff0c\u90a3\u4e48\u5982\u679c\u662f\u666e\u901a\u5c5e\u6027\u5982\u4e0b\uff1a<\/p>\n<pre><code>type \u4eba {     func $\u4eba(\u540d) {         $type = \u540d     } } <\/code><\/pre>\n<p>\u4e0a\u9762\u4e24\u79cd\u65b9\u6cd5\u5c31\u90fd\u53ef\u7528\u3002<\/p>\n<h3>1.3 \u952e in \u5b57\u5178<\/h3>\n<p>&#8230;&#8230;<\/p>\n<p>\u5b8c\u6574\u5185\u5bb9\u89c1\u539f\u6587\u94fe\u63a5\uff1a\u6728\u5170\u91cd\u751f\uff1a\u4e0e Python \u751f\u6001\u7684\u517c\u5bb9\u95ee\u9898\uff1b\u5b57\u7b26\u4e32\u63d2\u503c \uff08\u964d\u6743\uff0c\u53d1\u4e0d\u8d77\u5b8c\u6574\u7684\uff09<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6728\u5170\u91cd\u751f\uff1a\u4e0e Python \u751f\u6001\u7684&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/165824"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165824"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/165824\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165824"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}