{"id":5903,"date":"2022-08-18T14:21:06","date_gmt":"2022-08-18T06:21:06","guid":{"rendered":"http:\/\/139.9.1.231\/?p=5903"},"modified":"2022-08-18T14:21:07","modified_gmt":"2022-08-18T06:21:07","slug":"__call__","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/08\/18\/__call__\/","title":{"rendered":"__call__\u65b9\u6cd5\u548c\u53ef\u8c03\u7528\u5bf9\u8c61"},"content":{"rendered":"\n<p>\u5728\u770b\u795e\u7ecf\u7f51\u7edc\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u7c7b\u5b9a\u4e49\u4e2d\u603b\u662f\u4f1a\u51fa\u73b0__call__\u65b9\u6cd5\uff0c\u5b83\u662fPython\u7c7b\u4f53\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u7684\u4e00\u4e2a\u7279\u6b8a\u65b9\u6cd5\uff0c<strong><em>\u5b9a\u4e49\u4e86\u8be5\u65b9\u6cd5\u7684\u5bf9\u8c61\u79f0\u4e3a\u53ef\u8c03\u7528\u5bf9\u8c61\uff0c\u5373\u8be5\u5bf9\u8c61\u53ef\u4ee5\u50cf\u51fd\u6570\u4e00\u6837\u88ab\u8c03\u7528\u3002<\/em><\/strong><\/p>\n\n\n\n<p>\u5b9a\u4e49\u4e00\u4e2a\u53ef\u4ee5\u6c42\u89e3\u81ea\u7531\u843d\u4f53\u4e0b\u964d\u9ad8\u5ea6\u7684\u5bf9\u8c61<\/p>\n\n\n\n<p><strong>\u7c7b\u7684\u5b9e\u4f8b<\/strong>\uff1a\u5982\u679c\u7c7b\u5b9a\u4e49\u4e86\u00a0<code>__call__<\/code>\u00a0\u65b9\u6cd5\uff0c\u90a3\u4e48\u5b83\u7684\u5b9e\u4f8b\u53ef\u4ee5\u4f5c\u4e3a\u51fd\u6570\u8c03\u7528\u3002\u6bcf\u6267\u884c\u4e00\u6b21\u5b9e\u4f8b\uff0c__call__\u51fd\u6570\u5c31\u6267\u884c\u4e00\u904d\uff1a<\/p>\n\n\n\n<p><strong><em>\u53ef\u4ee5\u7406\u89e3\u4e3a \u5b9e\u4f8b() ==\u5b9e\u4f8b.__call__() <\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class GDistance:\r\n    def __init__(self, g):\r\n        self.g = g\r\n    def __call__(self, t):\r\n        # \u81ea\u7531\u843d\u4f53\u4e0b\u964d\u8ddd\u79bb s=g*t^2\r\n        return (self.g * t ** 2)\/2<\/code><\/pre>\n\n\n\n<p>\u8c03\u7528\u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>e_gdist = GDistance(9.8)\nfor t in range(11):\n    print(\"%d \u79d2 \u4e0b\u964d%.2f \u7c73\" %(t, <strong>e_gdist(t)<\/strong>))<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 \u79d2 \u4e0b\u964d0.00 \u7c73\n1 \u79d2 \u4e0b\u964d4.90 \u7c73\n2 \u79d2 \u4e0b\u964d19.60 \u7c73\n3 \u79d2 \u4e0b\u964d44.10 \u7c73\n4 \u79d2 \u4e0b\u964d78.40 \u7c73\n5 \u79d2 \u4e0b\u964d122.50 \u7c73\n6 \u79d2 \u4e0b\u964d176.40 \u7c73\n7 \u79d2 \u4e0b\u964d240.10 \u7c73\n8 \u79d2 \u4e0b\u964d313.60 \u7c73\n9 \u79d2 \u4e0b\u964d396.90 \u7c73\n10 \u79d2 \u4e0b\u964d490.00 \u7c73<\/code><\/pre>\n\n\n\n<p>\u603b\u4e4b\uff1a\u5982\u679c\u4e00\u4e2a\u7c7b\u4e2d\u5b9a\u4e49\u4e86 __call__ \u65b9\u6cd5\uff0c\u90a3\u4e48\u8be5\u7c7b\u7684\u5b9e\u4f8b\u53ef\u4ee5\u4f5c\u4e3a\u51fd\u6570\u8c03\u7528\uff0c\u5e76\u6267\u884c__call__\u65b9\u6cd5\u6240\u5b9a\u4e49\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<ol><li><strong>class<\/strong> CLanguage:<\/li><li># \u5b9a\u4e49__call__\u65b9\u6cd5<\/li><li><strong>def<\/strong> __call__(self,name,add):<\/li><li><strong>print<\/strong>(&#8220;\u8c03\u7528__call__()\u65b9\u6cd5&#8221;,name,add)<\/li><li><\/li><li>clangs = CLanguage()<\/li><li>clangs(&#8220;C\u8bed\u8a00\u4e2d\u6587\u7f51&#8221;,&#8221;http:\/\/c.biancheng.net&#8221;)<\/li><\/ol>\n\n\n\n<p>\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<p>\u8c03\u7528__call__()\u65b9\u6cd5 C\u8bed\u8a00\u4e2d\u6587\u7f51 http:\/\/c.biancheng.net<\/p>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u901a\u8fc7\u5728 CLanguage \u7c7b\u4e2d\u5b9e\u73b0 __call__() \u65b9\u6cd5\uff0c\u4f7f\u7684 clangs \u5b9e\u4f8b\u5bf9\u8c61\u53d8\u4e3a\u4e86\u53ef\u8c03\u7528\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>Python \u4e2d\uff0c\u51e1\u662f\u53ef\u4ee5\u5c06 () \u76f4\u63a5\u5e94\u7528\u5230\u81ea\u8eab\u5e76\u6267\u884c\uff0c\u90fd\u79f0\u4e3a\u53ef\u8c03\u7528\u5bf9\u8c61\u3002\u53ef\u8c03\u7528\u5bf9\u8c61\u5305\u62ec\u81ea\u5b9a\u4e49\u7684\u51fd\u6570\u3001Python \u5185\u7f6e\u51fd\u6570\u4ee5\u53ca\u672c\u8282\u6240\u8bb2\u7684\u7c7b\u5b9e\u4f8b\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u53ef\u8c03\u7528\u5bf9\u8c61\uff0c\u5b9e\u9645\u4e0a\u201c\u540d\u79f0()\u201d\u53ef\u4ee5\u7406\u89e3\u4e3a\u662f\u201c\u540d\u79f0.__call__()\u201d\u7684\u7b80\u5199\u3002\u4ecd\u4ee5\u4e0a\u9762\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u7684 clangs \u5b9e\u4f8b\u5bf9\u8c61\u4e3a\u4f8b\uff0c\u5176\u6700\u540e\u4e00\u884c\u4ee3\u7801\u8fd8\u53ef\u4ee5\u6539\u5199\u4e3a\u5982\u4e0b\u5f62\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">clangs.__call__(\"C\u8bed\u8a00\u4e2d\u6587\u7f51\",\"http:\/\/c.biancheng.net\")<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u770b\u795e\u7ecf\u7f51\u7edc\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u7c7b\u5b9a\u4e49\u4e2d\u603b\u662f\u4f1a\u51fa\u73b0__call__\u65b9\u6cd5\uff0c\u5b83\u662fPython\u7c7b\u4f53\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u7684\u4e00\u4e2a\u7279\u6b8a\u65b9\u6cd5\uff0c &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/08\/18\/__call__\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">__call__\u65b9\u6cd5\u548c\u53ef\u8c03\u7528\u5bf9\u8c61<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5903"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=5903"}],"version-history":[{"count":15,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5903\/revisions"}],"predecessor-version":[{"id":5918,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5903\/revisions\/5918"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=5903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=5903"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=5903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}